-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
2,058 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
''' | ||
配置文件 | ||
''' | ||
DEBUG = True |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.