python


DateFields not using custom DATE_FORMAT for output


I've followed Django's documentation in order to set the date output format for all the DateFields used in my project.
Despite this, dates are still not being rendered in the format I'm enforcing. They're being outputted as YYYY-mm-dd instead.
Here's my config:
settings.py
USE_L10N = False
DATE_FORMAT = '%d/%m/%Y'
SHORT_DATE_FORMAT = '%d/%m/%Y'
DATE_INPUT_FORMATS = [
'%d/%m/%Y', # '25/10/2006'
]
Is there something I'm missing here, or is this a bug with Django?
Are you specifying how the template engine should format your variable? You need to add the date tag where you output your variable in the template.
From the documentation:
If value is a datetime object (e.g., the result of datetime.datetime.now()), the output will be the string 'Wed 09 Jan 2008'.
When used without a format string, the DATE_FORMAT format specifier is used. Assuming the same settings as the previous example:
[...]
Meaning you have to do something like this:
{{ my_variable|date }}
With the help of FunkyBob on IRC, the issue has been resolved.
I was using a custom widget for my DateFields:
class CalendarWidget(forms.TextInput):
class Media:
css = {
'all': ('main/js/vendor/pickadate.js-3.5.6/lib/compressed/themes/default.css',
'main/js/vendor/pickadate.js-3.5.6/lib/compressed/themes/default.date.css',)
}
js = ('main/js/vendor/pickadate.js-3.5.6/lib/compressed/picker.js',
'main/js/vendor/pickadate.js-3.5.6/lib/compressed/picker.date.js',
'main/js/datepicker.min.js',)
I simply had to use forms.DateInput instead of forms.TextInput in order for it to output my dates in the correct format.

Related Links

Python shared list between modules
How to handle python inheritance properly
f = lambda n:(1,f(n-1)*n)[n>1] gives RunTimeError in Python 3
Call a Python function from a Jinja template
Python Struct Library appending unwanted Char 'L'
Python 3.4 Rock Paper Scissors
Timed Actions - Randomized
Split pandas column into two
Case insensitive field in Django
How to rewrite the code which appends to lists with numpy arrays
Figure in a figure in a figure
Cron job not working all the way. and Python is only half working on my script
Module vtkCommonCorePython not found in windows
Trying to use exec() to define a variable by setting a string equal to a numpy ndarray, but I get a syntax error. Python 2.7.10
Django Staticfiles not being served on Azure
Create virtualenv with most recent version of python

Categories

HOME
shopify
openssl
freepascal
raspbian
ubuntu-16.04
wxwidgets
laravel-4
netflix-feign
ipfs
ndis
jboss7.x
abcpdf
ctypes
equalizer
lenskit
opera-mini
cairo
prestodb
device-detection
nmake
esql
google-ima
thingsboard
memsql
codelite
owl-api
reactiveui
autofill
ivy
percentage
picturebox
backup-strategies
web-audio-api
nsurlconnection
color-scheme
bing-maps-api
npm-publish
redhat-datavirt
matlab-cvst
dwarf
search-box
qos
pdfkit
atlassian-crowd
manifest.mf
glkit
chessboard.js
visible
tuxedo
pagekit
mongo-c-driver
anti-cheat
difference
hyperthreading
webhdfs
ffserver
ibm-data-studio
adobe-indesign
git-checkout
scrollspy
epl
temp-tables
gyroscope-framework
korma
help-viewer
reserved-words
hamsterdb
driver-signing
asp.net-mvc-scaffolding
ruboto
backbone-relational
lame
mailcore
fortran77
cgpath
crocodoc
couchdb-lucene
legacy-code
jpf
viewdidload
cross-domain-policy
mysql-error-1045
scalaxb
rijndael
pantheios
linfu
kpi
economics

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App