How can I change the default Django date template format?
Within your template, you can use Django’s date filter. E.g.: <p>Birthday: {{ birthday|date:”M d, Y” }}</p> Gives: Birthday: Jan 29, 1983 More formatting examples in the date filter docs.
Within your template, you can use Django’s date filter. E.g.: <p>Birthday: {{ birthday|date:”M d, Y” }}</p> Gives: Birthday: Jan 29, 1983 More formatting examples in the date filter docs.
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
Some of settings are misused: STATIC_URL = ‘/static/’ – this is fine STATIC_ROOT = ‘/vira_app/template’ – nope, this is supposed to be some folder not really related to the project structure. In the end, on prod it can be a CDN URL or a folder on different server. So try changing it to something like … Read more
It looks like {{ data.0 }}. See Variables and lookups.
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
Use with: {% with “shop/”|add:shop_name|add:”/base.html” as template %} {% include template %} {% endwith %}
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 %}
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
I also had to write this code as a custom template tag recently. To handle all look-up scenarios, it first does a standard attribute look-up, then tries to do a dictionary look-up, then tries a getitem lookup (for lists to work), then follows standard Django template behavior when an object is not found. (updated 2009-08-26 … Read more
If you don’t want the HTML to be escaped, look at the safe filter and the autoescape tag: safe: {{ myhtml |safe }} autoescape: {% autoescape off %} {{ myhtml }} {% endautoescape %}