当前位置: 首页 > 后端技术 > Python

Flask项目实战-环境搭建

时间:2023-03-26 19:16:43 Python

环境路径配置myblog/├──apps│├──cms#background│├──forms.py#forms│├──__init__.py#初始化文件│├──models.py#数据库模板文件││└──views.py#viewfile│├──common#public││├──__init__.py││├──models.py││└──views.py│├──front#foreground││├──forms.py││├──__init__.py││├──models.py││└──views.py│└──__init__.py├──config.py├──myblog.py├──static└──templatesbasiclayouttestapps__init__.pyisemptycmsbackgroundapps/cms/views.py#cmsbusinesslogicfromflaskimportBlueprintbp=Blueprint('cms',__name__,url_prefix='/cms')@bp.route('/')defindex():return"cmspage"apps/cms/__init__.pyfrom.viewsimportbp-----###commonpubliclibraryapps/common/views.pyfromflaskimportBlueprintbp=Blueprint('common',__name__,url_prefix='/common')@bp.route('/')defindex():return"commonpage"apps/common/__init__.pyfrom.viewsimportbpfront前台apps/front/views.pyfromflaskimportBlueprintbp=Blueprint('front',__name__)@bp.route('/')defindex():return"frontpage"config.py配置文件DEBUG=Truemyblog.py主程序入口文件fromflaskimportFlaskfromapps.cms从apps.common导入bp作为cms_bp从apps.front导入bp作为common_bpapp.register_blueprint(front_bp)if__name__=="__main__":app.run(port=8080,host="0.0.0.0")原文链接:https://segmentfault.com/a/11...

猜你喜欢