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
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 name
s in this line:
return render_template('hello.html', name=name)