flask argument in render_template

前端 未结 1 1979
别那么骄傲
别那么骄傲 2021-01-21 11:20

The name as an argument to hello function is assigned None, but why the name in render_template will take the value of the name if provided in the url? Basically my question is

相关标签:
1条回答
  • 2021-01-21 11:51

    Flask is a framework and there is a lot of code behind the scenes (especially werkzeug) which does all the request processing, then it calls your view function and then it prepares a complete response.

    So the answer is, that Python does not know the URL, but Flask does and calls your view function either with the name (overwriting the default None) or without it.

    The name variable of the view function is passed to the template under the same name. Those are the two names in this line:

    return render_template('hello.html', name=name)
    
    0 讨论(0)
提交回复
热议问题