当前位置:网站首页>Flask framework learning: trailing slashes for routes
Flask framework learning: trailing slashes for routes
2022-08-11 05:33:00 【weixin_42576837】
URL redirect behavior
The trailing slash of the route is different, for example:
from flask import Flaskapp = Flask(__name__)@app.route('/')def index():return 'index page'@app.route('/qwe')def test():return 'test'if __name__ == '__main__':app.run()When accessing the route /qwe, the route should be written as /qwe, which can be accessed, but if it is written as /qwe/will report an error
/qweVisit
/qwe/Visit
The error code is 404: the resource corresponding to this url cannot be found
If the code is modified to:
@app.route('/qwe/')# followed by a slashdef test():return 'test'Both access methods are available, you can try it yourself.
Notice that when you enter /qwe in the browser address bar, it will automatically become /qwe/, this is because flask automatically redirects, check the returnStatus code: 

means that the accessed /qwe is permanently transferred to /qwe/, so the redirection is performed automatically.
So if the route does not have / at the end, you cannot add a slash when accessing it.
In addition, if you modify the code now to @app.route('/qwe'), remove the slashes and run it again, there will always be an error, because it keeps redirecting, then clear the browserJust cache it.
边栏推荐
- 群晖DS220+ 应用小笔记
- The most complete installation tutorial of Pytorch (one step)
- Map根据key值排序
- 分库分表之sharding-proxy
- 让你代码越来越高大上的技巧——代码规范,你得知道
- (三)性能实时监控平台搭建(Grafana+Prometheus+Node_explorer+Jmeter)
- JedisLock_Redis分布式锁实现_转载
- 普林斯顿微积分读本05第四章--求解多项式的极限问题
- Sub-database sub-table ShardingSphere-JDBC notes arrangement
- 2022 building welder (building a special type of work) examination questions and simulation test
猜你喜欢
随机推荐
MySQL索引
selenuim使用cookie登录京东
Win10远程连接(实现多用户同时连接)
StarUML使用心得
Thymeleaf
【ARM】rk3399挂载nfs报错
Configure checkstyle in IDEA
tensorflow代码翻译成pytorch代码 -详细教程+案例
一个月闭关直接面进大厂,这份Android面试笔记是真的牛逼
【嵌入式开源库】MultiTimer 的使用,一款可无限扩展的软件定时器
元宇宙社交应用,靠什么吸引用户「为爱发电」?
postman脚本的应用
UML基本概念——动态视图
Redis details
Linux中安装redis
You must understand - the nine built-in objects and four domain objects of JSP
Redis详解
(一)Docker安装Redis实战(一主二从三哨兵)
将double类型的数据转为字符串
2022建筑焊工(建筑特殊工种)考题及模拟考试









