python flask实战项目_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

为空

cms 后台

apps/cms/views.py #cms业务逻辑

from flask import Blueprint

bp = Blueprint('cms',__name__,url_prefix='/cms')

@bp.route('/')

def index():

return "cms page"

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 config

app = 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")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值