return redirect(url_for('index', var=var)) return render_template('index.html', var=var)
Are these two lines essentially the same thing?
What is the difference between the two functions?
render_template is a Flask function from the flask. templating package. render_template is used to generate output from a template file based on the Jinja2 engine that is found in the application's templates folder. Note that render_template is typically imported directly from the flask package instead of from flask.
The render function Combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text. You request a page and the render function returns it. The redirect function sends another request to the given url.
redirect
returns a 302 header to the browser, with its Location
header as the URL for the index
function. render_template
returns a 200, with the index.html template returned as the content at that URL.
On a much simpler note, consider this - If none of your endpoints rendered templates, and all your redirects were to url's of endpoints within your app, there would be nothing to render!
It's like pointing the way to a place that won't show itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With