How to get current URL in jinja2/flask (request.url not working)

You can use {{ url_for(request.endpoint) }}, it works.


For folks who have routes that require additional arguments, the accepted answer won't quite work, as mentioned by @lfurini.

The following will use the view's arguments when constructing the URL:

{{ url_for(request.endpoint, **request.view_args) }}

Find where you have similar code to this, usually found in controller.py or __ init__.py or views.py :

from flask import render_template
...

@app.route('/example/<arg1>/<arg2>')
def some_view_function(arg1, arg2):
    ...

    return render_template('path/to/your/template.html')

With render_template() are request and other variables available to you.