flask之定义URL

flask定义URL分为无参的URL与有参的URL

URL可以理解为网址

无参的URL指在定义的过程中,不需要定义参数

python 复制代码
@app.route('/profile')
def profile():
    return "这是个人中心"

有参的URL指的是带参数的URL

语法:

@app.route(网址路径/<参数名>)

def 方法名(参数名):

方法体

python 复制代码
@app.route('/blog/<blog_id>')
def blog_detail(blog_id):
    return "您查找的博客id为:%s"%blog_id

假定要传参数1,根目录是127.0.0.1:5000

输入的网址是127.0.0.1/5000/blog/1

参数也可以指定类型,类型有string,int,float,path,uuid,any

其中any类型指备选值中的任何一个

如果要传递多个参数,中间可以用/分隔开

相关推荐
To_OC7 小时前
Next.js + Redis 构建笔记系统:Redis Hash 实战与性能优化
redis·后端·next.js
安_8 小时前
如何构建和使用向量索引?HNSW 和 IVF 有什么区别?
python·ai
counting money9 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
坚持学习前端日记9 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
北斗落凡尘10 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
雪碧聊技术10 小时前
安装Python(保姆级教程)
python·版本更新·python下载
++==10 小时前
JSON和Python的 四种核心容器
python·json
demo007x10 小时前
Hermes-Agent 技术架构
前端·后端·agent
__zRainy__13 小时前
Node系列 · Node基础:net 模块
后端·node.js