How to change the default Django date template format?

I have dates in isoformat in db, %Y-%m-%d however when the date is passed to the template it appears somehow like Oct. 16, 2011 Oct. 16, 2011 .

Anyway, can I manipulate the format at all costs?

+87
django django-templates
Oct 12 '11 at 8:22
source share
4 answers
+45
12 Oct. '11 at 8:24
source share

Inside the template, you can use the Django date filter. For example:.

 <p>Birthday: {{ birthday|date:"M d, Y" }}</p> 

gives:

Birthday: January 29, 1983

Additional formatting examples in date filter documents .

+238
Oct 13 2018-11-11T00:
source share

Set both DATE_FORMAT and USE_L10N

To make changes for the entire site in Django 1.4.1, add:

 DATE_FORMAT = "Ymd" 

to settings.py file and edit:

 USE_L10N = False 

since l10n overrides DATE_FORMAT

This is documented at: https://docs.djangoproject.com/en/dev/ref/settings/#date-format

+25
Oct 23 '12 at 15:55
source share

To change the date format in the views.py file, then assign it to the template.

 # get the object details home = Home.objects.get(home_id=homeid) # get the start date _startDate = home.home_startdate.strftime('%m/%d/%Y') # assign it to template return render_to_response('showme.html' {'home_startdate':_startDate}, context_instance=RequestContext(request) ) 
+6
Apr 2 '13 at 7:26
source share



All Articles