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')

  

转载于:https://www.cnblogs.com/alicelai1319/p/10297082.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值