Flask项目实战-环境构建

Flask项目实战-环境构建 环境路径配置

myblog/ ├── apps │├── cms#后台 ││├── forms.py#表单 ││├── __init__.py# init文件 ││├── models.py# 数据库模板文件 ││└── views.py# 视图文件 │├── common#公用 ││├── __init__.py ││├── models.py ││└── views.py │├── front #前台 ││├── forms.py ││├── __init__.py ││├── models.py ││└── views.py │└── __init__.py ├── config.py ├── myblog.py ├── static └── templates

基础布局测试 apps
  • __init__.py
【Flask项目实战-环境构建】为空
cms 后台
  • apps/cms/views.py #cms业务逻辑
from flask import Blueprint bp = Blueprint('cms',__name__,url_prefix='/cms')@bp.route('/') def index(): return "cmspage"

  • apps/cms/__init__.py
from .views import bp

common 公共库
  • apps/common/views.py
from flask import Blueprint bp = Blueprint('common',__name__,url_prefix='/common') @bp.route('/') def index(): return "common page"

  • apps/common/__init__.py
from .views import bp

front 前台
  • apps/front/views.py
from flask import Blueprint bp = Blueprint('front',__name__) @bp.route('/') def index(): return "front page"

config.py 配置文件
DEBUG = True

myblog.py 主程序入口文件
from flask import Flask from apps.cms import bp as cms_bp from apps.common import bp as common_bp from apps.front import bp as front_bp import configapp = Flask(__name__) app.config.from_object(config)app.register_blueprint(cms_bp) app.register_blueprint(common_bp) app.register_blueprint(front_bp) if __name__ == "__main__": app.run(port=8080,host="0.0.0.0")

    推荐阅读