Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there a way to print the current URL in Jinja2/Flask?

E.g. if the current URL is http://www.domain.com/example/1/2

{{ request.path }} works and prints /example/1/2, but how to I get the full URL with http:// as well?

From the docs (here){{ request.url }} should work, but it doesn't yield anything.

Thanks

UPDATE

Here are the render/context args from views.py:

class EventDetailView(EventObjectMixin, FormView):     template_name = 'gig/public/about.html'     context_object_name = 'event'     form_class = EventPurchaseTicketForm      def get_context_data(self, **kwargs):         context = super(EventDetailView, self).get_context_data(**kwargs)      ...          return context 
like image 388
alias51 Avatar asked Oct 09 '14 10:10

alias51


1 Answers

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

like image 75
hugoxia Avatar answered Sep 23 '22 03:09

hugoxia