Within a Django template, you can use HttpRequest.build_absolute_uri to generate the current page URI with the following code:

{{ request.build_absolute_uri }}

If you are using this URL for a social media link, such as Facebook, Twitter, or Google+, you can also add the urlencode function to encode the uri you are generating.

{{ request.build_absolute_uri|urlencode }}

Next Steps

Check out Django for Beginners, a free online book on how to create and deploy multiple Django applications. Starting with a simple “Hello, World” application it progresses through multiple web applications of increasing complexity showing Django best practices along the way.