Recommendations for using FORMAT_MODULE_PATH

From what I read FORMAT_MODULE_PATHallows you to use custom formats.

How do I access the first value from DATETIME_INPUT_FORMATSin my application?

The variable DATETIME_INPUT_FORMATSfor german should be '%d.%m.%Y', while for English it should be '%Y-%m-%d'. I want to use the values ​​from formats.py files depending on the language.

I have followed the Django documentation on how to use a variable FORMAT_MODULE_PATH, but I am not getting the expected results.

settings.py:
    USE_L10N = True
    USE_I18N = True
    FORMAT_MODULE_PATH = 'myproject.formats'


myproject/
    formats/
        __init__.py
        en/
            __init__.py
            formats.py
        de/
            __init__.py
            formats.py

I change the browser language from English to German, and vice versa, and nothing happens with the date format. It is always '%Y-%m-%d'. The date format displayed is the value settings.DATE_INPUT_FORMATS[0].

Django version is 1.2.5, and Python version is 2.5.4.

0
2

, FORMAT_MODULE_PATH, , formats.get_format ('DATE_INPUT_FORMATS') [0]. .

0

Django 1.3 :

settings.py:

USE_I18N = True
USE_L10N = True
TIME_ZONE = 'Europe/Amsterdam'
LANGUAGE_CODE = 'nl_NL'
FORMAT_MODULE_PATH = 'settings.locale'

settings/locale/nl/formats.py:

DATETIME_FORMAT = 'j F Y \o\m H:i'
+1

Source: https://habr.com/ru/post/1793723/


All Articles