2

我希望在一个项目中定义很多常量。
我不想用它们污染 settings.py。
(如在 Django 中定义常量所述所述)

除了 settings.py 文件之外,您在哪里/如何在 django 中定义全局常量?

4

1 回答 1

1

Django settings.py is a good place to have your constants defined. Other option is to write your own template context processor. But just have a separate file where you define all of your constants and import them in settings file in this way your settings file will not be polluted:

settings.py

# other settings
# ----------

try:
    form my_constants import *
except ImportError:
    pass
于 2013-05-14T03:22:56.340 回答