Copyright © 2022-2025 aizws.net · 网站版本: v1.2.6·内部版本: v1.25.2·
页面加载耗时 0.00 毫秒·物理内存 125.9MB ·虚拟内存 1372.6MB
欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。

url传参方式
普通传参方式
@app.route('/p/<id>/')
def article_detail(id):
return '你访问的文章第%s篇'%id
指定参数类型
有以下几种类型:
string:默认的数据类型
int:接受整形
float:浮点型
path:和string的类似,但是接受斜杠
any:可以指定多个路径
uuid:只接受uuid字符串
相关推荐:《Python视频教程》
(1)any
@app.route('/<any(blog,user):url_path>/<id>')
def detail(url_path,id):
if url_path == 'blog':
return '博客详情%s'%id
else:
return '用户详情%s'%id

(2)path
@app.route('/article/<path:test>/')
def test_article(test):
return 'test_article:{}'.format(test)
获取参数
from flask import Flask,request
@app.route('/tieba/')
def tieba():
wd = request.args.get('wd')
return '获取的参数的是%s'%wd
cookie:在网站中,http请求是无状态的。也就是说即使第一次和服务器连接后并且登录成功后,第二次请求服务器依然不能知道当前请求是哪个用户。cookie的出现就是为了解决这个问题,第一次 ...