当前位置:网站首页>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.
边栏推荐
- Oracle常用语句归纳_持续更新
- Redis-使用jedis连接linux中redis服务器失败的解决方案
- Let's talk programming languages together
- [No 2022 Shanghai Security Officer A Certificate Exam Question Bank and Mock Exam
- 2022煤矿瓦斯检查考试题模拟考试题库及答案
- [ARM] rk3399 mounts nfs error
- flask框架学习:debug与配置项
- guava RateLimiter uniform current limit
- 金仓数据库 KingbaseGIS 使用手册(6.8. 几何对象输入函数)
- redis分布式锁
猜你喜欢
随机推荐
面试题整理
【Cron】学习:cron 表达式
Sub-database sub-table ShardingSphere-JDBC notes arrangement
pytorch和tensorflow函数对应表
UML基本概念——动态视图
【Mysql】----基础练习
阿里天池学习赛 新闻文本分类
四大函数式接口
redis连接idea
(三)Redis 如何进行压测
BGP综合实验
【嵌入式开源库】MultiTimer 的使用,一款可无限扩展的软件定时器
leetcode 9. Palindromic Numbers
flaks framework learning: adding variables to the URL
IDEA使用记录
Linux中安装redis
prometheus:(二)监控概述(你永远逃不出我的手掌哈哈)
报表控件Stimulsoft报告中的数据矩阵条形码介绍
StarUML使用心得
[Embedded open source library] The use of cJSON, an efficient and streamlined json parsing library









