什么类型的网站开发比较困难,网站网络结构设计,网站服务器是注册域名平台吗,广告设计基础知识Flask的URL规则基于werkzeug的路由模块#xff0c; 用来保证URL的唯一性。
例如带斜线#xff1a;
app.route(/example/)
def example():return ok如果访问一个结尾不带斜线的URL会被重定向到斜线的URL上。 #xff08;/example#xff09;变为(/example/)
如果不带斜线…Flask的URL规则基于werkzeug的路由模块 用来保证URL的唯一性。
例如带斜线
app.route(/example/)
def example():return ok如果访问一个结尾不带斜线的URL会被重定向到斜线的URL上。 /example变为(/example/)
如果不带斜线
app.route(/index)
def index():return ok上例子最后不带斜线如果我们访问一个带斜线的/index/ 就会产生一个404“Not Found”的错误。
app.route(/, endpoint1) 不能重名
endpoint 的值是唯一的同一模块中可以有同名的 view function 视图函数。对于 url_for 函数的参数如果使用函数名作为参数则无法确定其 url 使用 endpoint 作为参数则保证了 url_for 返回确定的 url 。flask.url_for 需要通过 endpoint 得到 url 可以避免匿名函数的问题。
code# encoding: utf-8
from flask import FlaskappFlask(__name__)app.route(/,endpointgood)
def index():
return Good jodapp.route(/int:id,endpointbad)
def index(id):
return %s%idif __name__ __main__:
app.run()
/code