views:

252

answers:

1

Hay, i was wondering how to get the current URL within a template.

Say my URL was

/user/profile/

How do i return this to the template?

Thanks

+3  A: 

request.get_full_path

Ignacio Vazquez-Abrams
Can i get it without passing the 'request' variable to the template?
dotty
I believe request is always passed to the template... if not, render_to_response('template.html',{},context_instance=RequestContext(request)) .. at that point, request is definitely passed in.
Brant
Bascially i'm making a 'logout' function which redirects back to the page they were on when a 'logout' button is clicked. I was going to append the current URL to the query string.
dotty
Just use request.path then
Brant
I decided to use request.META['HTTP_REFERER'] to redirect them.
dotty
Be warned that HTTP_REFERRER isn't always reliable. Many of the "Internet Security Suites" will remove that variable. It is probably worth it to ensure that your site still works even when there isn't a referrer, using something like `request.META.get('HTTP_REFERRER', '/')` or similar.
Jack M.