Full page URL on page template
May. 19th, 2010 02:57 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
Say you need the full URL of the current page you're displaying that you need to use on the template of that page. (For example, to add links to Facebook, Delicious, etc., and you don't want to have additional JavaScript that you didn't write on your pages. Shush, yes, I'm a control freak. :P) Also say that you don't want to use the sites framework to hack it together. The permalink decorator won't work, either, because that gives you the relative link.
Thankfully, there's a new request object that's been added to 1.0 that will do it.
To use it, include the bolded bit in your
Then you can use the
<a href="http://www.facebook.com/sharer.php?u={{ link|urlencode }}&t={{ title|urlencode }}">
Thankfully, there's a new request object that's been added to 1.0 that will do it.
To use it, include the bolded bit in your
views.py
file, as part of each view where you want to have the variable available: return render_to_response('dir/template.html', {'object': obj, 'link': request.build_absolute_uri()}, RequestContext(request))
Then you can use the
link
variable on the template where you need the URL:<a href="http://www.facebook.com/sharer.php?u={{ link|urlencode }}&t={{ title|urlencode }}">
(no subject)
Date: 2010-05-19 10:43 pm (UTC)(no subject)
Date: 2010-05-19 11:00 pm (UTC)