Skip to content

Commit

Permalink
co
Browse files Browse the repository at this point in the history
  • Loading branch information
jornsky committed Jul 24, 2019
1 parent ce9490d commit 327deea
Show file tree
Hide file tree
Showing 49 changed files with 2,058 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .idea/blog.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

596 changes: 596 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
flask = "*"
cymysql = "*"
flask-sqlalchemy = "*"
flask-login = "*"
flask-ckeditor = "*"
wfforms = "*"
wtf = "*"
wtforms = "*"

[requires]
python_version = "3.6"
126 changes: 126 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
python模块的初始化文件夹
以及Flask的初始化文件 定义了模板位置,静态文件的存放位置
"""
from flask import Flask
from app.models.base import db
from flask_login import LoginManager
from flask_ckeditor import CKEditor

#富文本编辑器
ckeditor = CKEditor()
login_manager = LoginManager()
def create_app():
app = Flask(__name__,template_folder='templates',static_folder='static')
app.config.from_object('app.setting')
app.config.from_object('app.secure')
#注册模块蓝图
register_web_blueprint(app)


#注册数据库

db.init_app(app)
db.create_all(app=app)

#初始化login
login_manager.init_app(app)
#初始化登入野页面
login_manager.login_view='web.login'
login_manager.login_message_category='warning'
login_manager.login_message=u'请先登入!'

ckeditor.init_app(app)


return app


#蓝图和app绑定
def register_web_blueprint(app):
from app.web import web
app.register_blueprint(web)

Binary file added app/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added app/__pycache__/secure.cpython-36.pyc
Binary file not shown.
Binary file added app/__pycache__/setting.cpython-36.pyc
Binary file not shown.
Binary file added app/models/__pycache__/base.cpython-36.pyc
Binary file not shown.
Binary file added app/models/__pycache__/category.cpython-36.pyc
Binary file not shown.
Binary file added app/models/__pycache__/post.cpython-36.pyc
Binary file not shown.
Binary file added app/models/__pycache__/post_category.cpython-36.pyc
Binary file not shown.
Binary file added app/models/__pycache__/user.cpython-36.pyc
Binary file not shown.
26 changes: 26 additions & 0 deletions app/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer

db = SQLAlchemy()

# 定义多对多2张表的关系
# post_category = db.Table('post_category',
# db.Column('post_id',db.Integer,db.ForeignKey('post.id'),primary_key=True),
# db.Column('category_id',db.Integer,db.ForeignKey('category.id'),primary_key=True)
#
# )


class Base(db.Model):
#不创建这个表 作为基类
__abstract__ = True
create_time = Column('create_time',Integer)

#为对象动态赋值
def set_attrs(self,attrs_dict):
for k,v in attrs_dict.items():
if hasattr(self,k) and k!='id':
setattr(self,k,v)



19 changes: 19 additions & 0 deletions app/models/category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from sqlalchemy import Integer, String,Column
from sqlalchemy.orm import relationship

from app.models.base import Base, db
from app.models.post_category import Post_category


class Category(Base):
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(50),nullable=False,unique=True)

#反向调用 post.categorys.append(<class(Category)>) secondary 关系表
posts = relationship('Post', secondary=Post_category.__table__,
backref=db.backref('categorys', lazy='dynamic'))





21 changes: 21 additions & 0 deletions app/models/post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sqlalchemy import Column, String, Integer, SmallInteger
from sqlalchemy.orm import relationship

from app.models.base import Base, db
from app.models.post_category import Post_category


class Post(Base):
id = Column(Integer, primary_key=True, autoincrement=True)
author = Column(String(30),nullable=False)
title = Column(String(200),nullable=False)
content = Column(String(1000),nullable=False)









18 changes: 18 additions & 0 deletions app/models/post_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from sqlalchemy import Integer, String, Column, ForeignKey
from sqlalchemy.orm import relationship

from app.models.base import Base


#多对多的关系表 关联user和post表
class Post_category(Base):

id = Column(Integer, primary_key=True, autoincrement=True)
post = relationship('Post')
pid = Column(Integer,ForeignKey('post.id'))

category = relationship('Category')
cid = Column(Integer,ForeignKey('category.id'))



43 changes: 43 additions & 0 deletions app/models/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from flask_login import UserMixin
from sqlalchemy import Column, String, Integer, SmallInteger
from werkzeug.security import generate_password_hash, check_password_hash

from app import login_manager
from app.models.base import Base


class User(UserMixin, Base):
id = Column(Integer, primary_key=True, autoincrement=True)
nicename = Column(String(50),nullable=False)
email = Column(String(100),nullable=False)
_password = Column('password',String(128))
create_time = Column(String(100))
status = Column(SmallInteger,default=0)
counts = Column(Integer,default=0)

#属性的读取和写入 getter setter 预处理
@property
def password(self):
return self._password

@password.setter
def password(self,raw):
self._password = generate_password_hash(raw)


def check_password(self,raw):
return check_password_hash(self._password,raw)

# usr Modele继承UserMxxin 和这个注解 就可以使用curret_user
@login_manager.user_loader
def load_user(uid):
return User.query.get(int(uid))









3 changes: 3 additions & 0 deletions app/secure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SQLALCHEMY_DATABASE_URI='mysql+cymysql://root:123456@localhost:3306/blog'
SECRET_KEY='\cx\cx\cx\cx'

4 changes: 4 additions & 0 deletions app/setting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'''
配置文件
'''
DEBUG = True
6 changes: 6 additions & 0 deletions app/static/css/bootstrap.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit 327deea

Please sign in to comment.