Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

wechat 虚幻 609℃ 0评论

后台管理员账户相关页面搭建

一、账户登录相关页面

1.创建User对象文件

2.创建login,edit,reset-pwd方法

3.创建对应的视图层

二、账户管理相关页面

1.创建Account

2.创建index,set,info方法

3.创建对应视图层

三、实战

3.1创建login

创建user文件夹,并创建User.py文件:

20210720220446 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

文件内容如下:

# -*- coding: utf-8 -*-
from flask import Blueprint

route_user = Blueprint('user_page', __name__)

@route_user.route("/login")
def login():
    return "login"

www.py中引入route_user

# -*- coding: utf-8 -*-
from application import app
from web.controllers.index import route_index
from web.controllers.user.User import route_user

app.register_blueprint( route_index,url_prefix = "/" )
app.register_blueprint( route_user,url_prefix = "/user" )

运行:

20210720221112 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

3.2渲染页面

User.py

# -*- coding: utf-8 -*-
from flask import Blueprint,render_template

route_user = Blueprint('user_page', __name__)

@route_user.route("/login")
def login():
    return render_template("user/login.html")

statictemplates复制到这个文件夹下

静态资源下载地址:

链接:https://pan.baidu.com/s/1SLRWMq8dmxJWWxlO2TIP3A
提取码:xvg5

20210720221716 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

application.py添加模板的路径引用

20210720222837 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

拷贝UrlManager.pylibs文件夹下

20210720222725 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

将函数模板引入进来:

20210720223426 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

'''
将函数注入到模板中
'''
from common.libs.UrlManager import UrlManager
app.add_template_global(UrlManager.buildStaticUrl, 'buildStaticUrl')
app.add_template_global(UrlManager.buildUrl, 'buildUrl')

运行:

20210720223330 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

但是这里图片没有被正常的渲染。

原因是因为样式文件加载失败:

20210720224516 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

创建static.py文件

# -*- coding: utf-8 -*-
from flask import Blueprint,send_from_directory
from application import app
route_static = Blueprint('static', __name__)

@route_static.route("/<path:filename>")
def index( filename ):
    return send_from_directory(  app.root_path + "/web/static/" ,filename )

20210720225018 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

application.py添加root_path

20210720230154 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

www.py中引入route_static

# -*- coding: utf-8 -*-
from application import app
from web.controllers.index import route_index
from web.controllers.user.User import route_user
from web.controllers.static import route_static

app.register_blueprint( route_index,url_prefix = "/" )
app.register_blueprint( route_user,url_prefix = "/user" )
app.register_blueprint( route_static,url_prefix = "/static" )

运行:

20210720230214 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

可以看到成功加载文件。

3.3构建仪表盘页面

index.py渲染index.html模板

20210720231112 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

运行:

20210720230832 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

Uer.py中渲染编辑页面和重置密码页面

20210720231851 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

3.4添加账号管理页面

添加Account.py并添加url地址

20210720232717 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

www.py中引入route_account

# -*- coding: utf-8 -*-
from application import app
from web.controllers.index import route_index
from web.controllers.user.User import route_user
from web.controllers.static import route_static
from web.controllers.account.Account import route_account

app.register_blueprint( route_index,url_prefix = "/" )
app.register_blueprint( route_user,url_prefix = "/user" )
app.register_blueprint( route_static,url_prefix = "/static" )
app.register_blueprint( route_account,url_prefix = "/account" )

运行:

20210720233229 - Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

转载请注明:虚坏叔叔 » Python flask实战订餐系统微信小程序-15后台管理员账户相关页面搭建

喜欢 (2)

您必须 登录 才能发表评论!