How do I get the domain name of my current site from within a Django template? I've tried looking in the tag and filters but nothing there.
Python – How to get the domain name of the site within a Django template
djangodjango-templatespython
Related Topic
- Python – Convert bytes to a string
- Python – How to sort a dictionary by value
- How to get the current URL within a Django template
- Python – How to get the full path of the current file’s directory
- Python – Importing files from different folder
- Python – How to install packages using pip according to the requirements.txt file from a local directory
- Python – How to iterate over rows in a DataFrame in Pandas
Best Answer
If you want the actual HTTP Host header, see Daniel Roseman's comment on @Phsiao's answer. The other alternative is if you're using the contrib.sites framework, you can set a canonical domain name for a Site in the database (mapping the request domain to a settings file with the proper SITE_ID is something you have to do yourself via your webserver setup). In that case you're looking for:
you'd have to put the current_site object into a template context yourself if you want to use it. If you're using it all over the place, you could package that up in a template context processor.