【问题标题】:How to extend the settings file in Django?如何在 Django 中扩展设置文件?
【发布时间】:2020-02-29 18:29:46
【问题描述】:

我正在使用Constance - Dynamic Django settings 在我的项目中配置一些值。 根据 Constance,我应该在 settings.py 文件中添加所有配置。 但我需要将此配置分隔在另一个文件中。 我尝试通过执行下面的代码来扩展设置文件,但它不起作用 它没有从那个新文件中读取值。

from .settings import *


CONSTANCE_ADDITIONAL_FIELDS = {
'corres_format_select': ['django.forms.fields.ChoiceField', {
    'widget': 'django.forms.Select',
    'choices': (("xx - xx", "xx - xx"), ("xx/xx", "xx/xx"), ("xx : xx", "xx : xx"))}],

'date_format_select': ['django.forms.fields.ChoiceField', {
    'widget': 'django.forms.Select',
    'choices': (("dd/mm/yyyy", "dd/mm/yyyy"), ("mm/dd/yyyy", "mm/dd/yyyy"), ("dd-mm-yyyy", "dd-mm-yyyy"))}],
}

CONSTANCE_CONFIG = {
'Correspondence_format': ("xx - xx", 'Choose the correspondce format', 'corres_format_select'),
'Date_format': ("dd/mm/yyyy", 'Choose the date format', 'date_format_select'),
} 

【问题讨论】:

  • 不,因为我需要项目使用默认 settings.py 但我也需要它从另一个文件中读取更多值。

标签: python django


【解决方案1】:

写入另一个文件并导入到设置文件中

【讨论】:

  • 是的!我在默认的settings.py中导入新文件
【解决方案2】:

您需要将您的 manage.py 和 uwsgi.py 文件指向该新文件而不是 settings.py。

【讨论】:

  • 我不这么认为,因为我不想替换设置文件我只想扩展它
  • 好的,这非常令人困惑。请说明您的意图。
猜你喜欢
  • 2015-01-28
  • 2012-07-22
  • 1970-01-01
  • 2016-02-28
  • 1970-01-01
  • 2015-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多