Flask--(登录注册)抽取视图函数

视图函数抽取:
在info目录下准备视图业务模块包:modules
在modules中添加首页模块包index
在index包的__init__中导入蓝图
在index的__init__创建蓝图
在index包中创建views文件,添加index视图函数
在info的__init__的app中注册蓝图
在视图函数中存入值到redis_store:
解决redis_store是app中局部变量的问题
全局定义为 redis_store = None
使用的时候,global redis_store
解决制图函数中循环导入redis_store报错的问题
app中,在哪里用就在哪里导入
解决视图函数中使用redis_store没有智能提示的问题:
在app中定义全局变量时,声明类型
redis_store = None #type:StrictRedis
或者redis_store:StrictRedis = None

  

 视图函数添加蓝图,并注册蓝图

from flask import current_app
from flask import render_template from info import redis_store
from . import index_blu @index_blu.route("/")
def index(): return render_template('news/index.html') @index_blu.route("/favicon.ico")
def favicon(): return current_app.send_static_file('news/favicon.ico') #业务模块init文件中定义蓝图
from flask import current_app
from flask import render_template from info import redis_store
from . import index_blu @index_blu.route("/")
def index(): return render_template('news/index.html') @index_blu.route("/favicon.ico")
def favicon(): return current_app.send_static_file('news/favicon.ico')

  

上一篇:robotium和appium的一些区别


下一篇:java入门第一季2