Extending an existing list in Django settings

I am trying to allow the input of more flexible dates in my application and would like to use the default Django settings. In the documentation, I can define DATE_INPUT_FORMATSin settings.py, but I would like to keep the defaults and add a few others.

I tried to expand it, as if it already existed, which failed miserably:

DATE_INPUT_FORMATS += ['%m-%d-%y',]

Productivity: NameError: name 'DATE_INPUT_FORMATS' is not defined

I also tried importing the default settings from django.conf, but it is circular because it is trying to enable mine settings.py, which I am loading.

from django.conf import settings as default_settings
DATE_INPUT_FORMATS = default_settings.DATE_INPUT_FORMATS
DATE_INPUT_FORMATS += ['%m-%d-%y',]

Productivity:

Error: Can't find the file 'settings.py' in the directory containing './manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it causing an ImportError somehow.)

What is the correct way to extend the default value in Django settings.py?

+3
source share
2 answers

You must be able to import the form. django.conf.global_settings

+6

, . , , , .

django django.conf.global_settings.py .

DATE_INPUT_FORMATS = (
    '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06'
    '%b %d %Y', '%b %d, %Y',            # 'Oct 25 2006', 'Oct 25, 2006'
    '%d %b %Y', '%d %b, %Y',            # '25 Oct 2006', '25 Oct, 2006'
    '%B %d %Y', '%B %d, %Y',            # 'October 25 2006', 'October 25, 2006'
    '%d %B %Y', '%d %B, %Y',            # '25 October 2006', '25 October, 2006'

        '%m-%d-%y'        # <-- Yours
)
0

All Articles