TJ Desantes
TJ Desantes

Reputation: 245

How to get the current URL of a page in a Django template?

I know there is another question with virtually the same title as mine but the solution in that one didn't work for me. My url is like this:

http://domain.com/videos/dvd/1/

If I use either {{baseurl}} or {{ request.get_full_path }} I get just this part:

http://domain.com/videos/

How can I get the entire url? I need to be able to do this from the template level.

EDIT

P.S. it should disregard any parameters that may be in the url.

Upvotes: 5

Views: 6198

Answers (1)

Ken Cochrane
Ken Cochrane

Reputation: 77415

You could get it in your view and pass it along into your template context so that it is available to you there.

https://docs.djangoproject.com/en/1.3/ref/request-response/#django.http.HttpRequest.build_absolute_uri

full_url = request.build_absolute_uri(None)

# pass full_url into the template context.

Upvotes: 9

Related Questions