Flask之Flask实例有哪些参数
常用的参数应用实例
- from flask import Flask, render_template, url_for, session, request, redirect
- app = Flask(__name__, template_folder="templates111", static_folder="jingtaimulu", static_url_path='/static') # √
- app.secret_key = "wang"
- def confirm(func):
- def inner(*args, **kwargs):
- if session.get('auth'):
- return func(*args, **kwargs)
- else:
- next_url = request.path[1:]
- return redirect(url_for("login") + f"?next={next_url}")
- return inner
- @app.route('/', endpoint="index")
- @confirm
- def index():
- return "index"
- @app.route('/login', methods=["GET", "POST"])
- def login():
- msg = ""
- if request.method == "POST":
- auth = request.form.get("auth")
- if auth:
- session["auth"] = auth
- next_url = request.args.get("next", "index")
- return redirect(url_for(next_url))
- else:
- msg = "error"
- return render_template("login.html", msg=msg)
- @app.route('/shopping/', endpoint="shopping")
- def shopping():
- return "Shopping"
- if __name__ == '__main__':
- app.run(debug=True)
参数解析
- class Flask(_PackageBoundObject)
- def __init__(
- self,
- import_name,
- static_url_path=None, # 静态文件的访问路径, 就相当于别名, 类似于django中的 {% load static %}, 资源的url开头就是这里指定的路径
- static_folder='static', # 静态文件目录的路径 默认当前项目中的static目录
- static_host=None, # 远程静态文件所用的Host地址, 如CDN的主机地址
- host_matching=False, # 是否开启host主机位匹配,是要与static_host一起使用,如果配置了static_host, 则必须赋值为True
- subdomain_matching=False, # 理论上来说是用来限制SERVER_NAME子域名的,但是目前还没有感觉出来区别在哪里
- template_folder='templates', # template模板目录, 默认当前项目中的 templates 目录
- instance_path=None, # 指向另一个Flask实例的路径
- instance_relative_config=False, # 是否加载另一个实例的配置
- root_path=None # 主模块所在的目录的绝对路径,默认项目目录
Flask之Flask实例有哪些参数的更多相关文章
- Flask中的路由、实例化参数和config配置文件
Flask中的路由 endpoint 别名不能重复,对应的视图函数,默认是视图函数名.endpoint 才是路由的核心.视图函数与路由的对应关系.可以通过url_for 反向创建url # metho ...
- 七十八:flask.Restful之flask-Restful标准化返回参数以及准备数据
对于一个视图函数,可以指定好数据结构和字段用于返回,以后使用ORM模型或者自定义的模型的时候,它会自动获取模型中相应的字段,生成json数据,然后再返回给前端,这需要导入flask_restful.m ...
- Flask实现RESTful API(注意参数位置解析)
准备工作 首先安装flask_restful三方组件 pip install flask_restful 在models.py中新建一个类,生成表,往里面插入一些数据.(flask要想使用ORM的话需 ...
- Flask基础-基础实例
1. 10行代码的迷你程序 flask项目 from flask import Flask app = Flask(__name__) @app.route("/index") d ...
- flask之instance_path实例路径
Flask 0.8 introduces instance folders. Flask for a long time made it possible to refer to paths rela ...
- 七十九:flask.Restful之flask-Restful标准化返回参数示例
接上一篇的代码和数据 对于复杂结构的数据如果只是定义单一结构的话返回的数据就没意义了,此时定义的数据结构需精确到所有数据的每一个字段有时候要返回的数据结构中,会有比较复杂的数据结构,证实后可以使用一些 ...
- [Flask]学习Flask第三天笔记总结
from flask import Flask,render_template,request from others import checkLogin app = Flask(__name__) ...
- Flask01 初识flask、flask配置
1 什么是flask Flask是一个使用 Python 编写的轻量级 Web 应用框架.其 WSGI 工具箱采用 Werkzeug ,模板引擎则使用 Jinja2 . 百度百科:点击前往 中文文档: ...
- flask中Flask()和Blueprint() flask中的g、add_url_rule、send_from_directory、static_url_path、static_folder的用法
1.Blueprint()在蓝本注册函数register_blueprint()中,第一个参数为所注册的蓝本名称.当我们在应用对象上注册一个蓝图时,需要指定一个url_prefix关键字 参数(这个参 ...
随机推荐
- Vue2.0中的系统指令
v-on注册事件 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- golang rest api example
package main import ( "net/http" "github.com/gin-gonic/gin" "github.com/jin ...
- Batch Normalization 笔记
原理 BN的效果 Why BN works? 原理 输入层可以归一化,那么其他层也应该可以归一化.但是有个重要的问题,为什么要引入beta和gamma. 为什么要引入beta和gamma 不总是要标准 ...
- February 4 2017 Week 5 Saturday
It takes a great man to be a good listener. 懂得倾听的人才是真的了不起. Don't make comments before you have learn ...
- MapReduce过程详解(基于hadoop2.x架构)
本文基于hadoop2.x架构详细描述了mapreduce的执行过程,包括partition,combiner,shuffle等组件以及yarn平台与mapreduce编程模型的关系. mapredu ...
- CF839D Winter is here
题目分析 显然我们不可能直接计算每一个子序列的贡献,而应该计算对于每一个gcd对答案的贡献. 考虑容斥.按照套路: 设\(q(i)\)表示序列\(gcd\)为\(i\)的倍数的序列长度和. 设\(g( ...
- 显卡 GPU 关系
https://zhidao.baidu.com/question/1238935513507031339.htmlGraphic Processing Unit,意思就是图形处理器啊,显卡的由GPU ...
- UVA11987 【Almost Union-Find】
这是一道神奇的题目,我调了大概一天多吧 首先hack一下翻译,操作3并没有要求查询后从其所在集合里删除该元素 于是我们来看一下这三个操作 第一个合并属于并查集的常规操作 第三个操作加权并查集也是可以解 ...
- CF739B Alyona and a tree
嘟嘟嘟 前缀和+倍增+树上差分 假设\(v\)是\(u\)子树中的一个点,那么\(u\)能控制\(v\)的条件是受\(v\)的权值的限制,而并非\(u\).因此我们就能想到计算每一个点的贡献,即\(v ...
- mybatis分步查询与延迟加载
1.分步查询 先查询用户的部门 部门Mapper.xml <resultMap id="rMap" type="com.yunqing.mybatis.bean.D ...