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

django 1.5 – How to use variables inside static tag

You should be able to concatenate strings with the add template filter: {% with ‘assets/flags/’|add:request.LANGUAGE_CODE|add:’.gif’ as image_static %} {% static image_static %} {% endwith %} What you are trying to do doesn’t work with the static template tag because it takes either a string or a variable only: {% static “myapp/css/base.css” %} {% static variable_with_path … Read more

How to add url parameters to Django template url tag?

First you need to prepare your url to accept the param in the regex: (urls.py) url(r’^panel/person/(?P<person_id>[0-9]+)$’, ‘apps.panel.views.person_form’, name=”panel_person_form”), So you use this in your template: {% url ‘panel_person_form’ person_id=item.id %} If you have more than one param, you can change your regex and modify the template using the following: {% url ‘panel_person_form’ person_id=item.id group_id=3 %}

Django, creating a custom 500/404 error page

Under your main views.py add your own custom implementation of the following two views, and just set up the templates 404.html and 500.html with what you want to display. With this solution, no custom code needs to be added to urls.py Here’s the code: from django.shortcuts import render_to_response from django.template import RequestContext def handler404(request, *args, … Read more