In Django templates, is there a variable in the context (e.g. {{ BASE\_URL }}, {{ ROOT\_URL }}, or {{ MEDIA\_URL }} that one can use to link to the home url of a project?
I.e. if Django is running in the root of a project, the variable (let’s call it R) {{ R }} in a template would be /. If the root url is a sub-folder http://host/X/ the variable {{ R }} would be /X/ (or http://host/X/).
It seems painfully simple, but I can’t find an answer. 🙂 Thank you!
You could give the URL configuration which you’re using to handle the home page a name and use that:
urls.py:
Templates:
UPDATE: Newer versions of Django require quotation marks around the name of the view:
This note in the Django Book has some tips about deploying your applications to a subdirectory:
http://www.djangobook.com/en/1.0/chapter20/#cn43