分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

Flask中URL构建

发布时间:2023-09-06 02:05责任编辑:蔡小小关键词:暂无标签
Flask QuickStart Refence

URL Building

To build a URL to a specific function, use the url_for() function. It accepts the name of the function as its first argument and any number of keyword arguments, each corresponding to a variable part of the URL rule. Unknown variable parts are appended to the URL as query parameters.

Flask 快速参考相关(译文)

URL 构建

url_for() 函数用于构建指定函数的 URL。第一个参数为函数名,同时可以有多个对应于URL中变量的关键字参数,而未知变量将添加到 URL 中作为查询参数。

举例说明

from flask import Flask, url_forapp = Flask(__name__)@app.route(‘/‘)def index(): ???return ‘index‘@app.route(‘/login‘)def login(): ???return ‘login‘@app.route(‘/user/<username>‘)def profile(username): ???return ‘{}\‘s profile‘.format(username)with app.test_request_context(): ???print(url_for(‘index‘)) ???print(url_for(‘login‘)) ???print(url_for(‘login‘, next=‘/‘)) ???print(url_for(‘profile‘, username=‘John Doe‘))//login/login?next=//user/John%20Doe

Flask中URL构建

原文地址:http://blog.51cto.com/huanghai/2149220

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved