zoukankan      html  css  js  c++  java
  • 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')
    

      

  • 相关阅读:
    js高级-闭包
    js作用域
    js执行上下文与执行上下文栈
    js原型及原型链
    去除数组中重复的元素值
    树[省选联考2020]
    GDOI2020 游记
    Problem b[HAOI2011]
    分零食[JSOI2012]
    移动金币「SDOI2019」
  • 原文地址:https://www.cnblogs.com/alicelai1319/p/10297082.html
Copyright © 2011-2022 走看看