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

      

  • 相关阅读:
    端午节习俗
    彩绘漂亮MM集
    高效使用数码相机的诀窍
    项目管理缩略语
    数码相机如何当做摄像头(文字版)
    标签式按纽
    显示一个Form中的所有内容
    生活中要常常鼓励别人
    青苹果论坛重新开放
    第一次爱的人
  • 原文地址:https://www.cnblogs.com/alicelai1319/p/10297082.html
Copyright © 2020-2023  润新知