How can I get the domain name of my site within a Django template?

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 … Read more

How to access a dictionary element in a Django template?

choices = {‘key1′:’val1’, ‘key2′:’val2′} Here’s the template: <ul> {% for key, value in choices.items %} <li>{{key}} – {{value}}</li> {% endfor %} </ul> Basically, .items is a Django keyword that splits a dictionary into a list of (key, value) pairs, much like the Python method .items(). This enables iteration over a dictionary in a Django template.

Django TemplateDoesNotExist?

First solution: These settings TEMPLATE_DIRS = ( os.path.join(SETTINGS_PATH, ‘templates’), ) mean that Django will look at the templates from templates/ directory under your project. Assuming your Django project is located at /usr/lib/python2.5/site-packages/projectname/ then with your settings django will look for the templates under /usr/lib/python2.5/site-packages/projectname/templates/ So in that case we want to move our templates to … Read more

AngularJS with Django – Conflicting template tags

For Angular 1.0 you should use the $interpolateProvider apis to configure the interpolation symbols: http://docs.angularjs.org/api/ng.$interpolateProvider. Something like this should do the trick: myModule.config(function($interpolateProvider) { $interpolateProvider.startSymbol(‘{[{‘); $interpolateProvider.endSymbol(‘}]}’); }); Keep in mind two things: mixing server-side and client-side templates is rarely a good idea and should be used with caution. The main issues are: maintainability (hard to … Read more