When you build a website you'll probably eventually want to create some links to allow readers to easily submit your content to social bookmarking and news aggregation services. Fortunately it is pretty easy to add this functionality to your Django application.
Making the template
The template is the most complex part of this endeavour, but is still very simple (this should be a good sign). In the template I am assuming that you'll have be using generic views, and thus the content will be named 'object'. If you are using custom views you may have named your content containing variable something else. Also note that you'll need to have a get_absolute_url method for your object.
The template also needs access to your site, but we'll deal with making the site available to the template a bit later on.
You'll notice they we are using the urlencode filter on all of the strings we build, this is important because we'll be passing them as arguments to the urls that serve as the public api for the social sites we are communicating with.
You'll want to include the above template snippet inside the template you are submitting to the social sites. I usually do it with an include statement:
Which will simply inject that social code into the template directly (much easier than manually pasting it into multiple templates).
The Template Context
As mentioned above we also need to have access to our Site instance. The site is needed because we have no other way to figure out our full url for our content. We use the get_absolute_url method to get everything except the domain name, but we still need to get the domain name somehow (this means that our Site domain name needs to be the full domain name we want our urls to include www.lethain.com, for example).
Writing the context is also easy. First, make a new file in your application folder (I named mine context.py) and add these lines to it: