app.route使用

  1. app.route('/')
  2. def hello_word():
  3. return "hello word"

app.route() 会将url / 和相应的视图函数绑定
我们可以用url_for(‘hello_word’) 反转得到 url ‘/‘
endpoint 可以给这个url 重命名

@app.route('/',endpoint='index')
def hello_word():
    return "hello word"

url_for('index')

add_url_rule

@setupmethod
    def add_url_rule(
        self,
        rule,
        endpoint=None,
        view_func=None,
        provide_automatic_options=None,
        **options
    ):
app.add_url_rule('/test/',endpoint='mytest',view_func=mytest)