gpt4 book ai didi

python - 为什么我需要 DJANGO_SETTINGS_MODULE 集?

转载 作者:太空狗 更新时间:2023-10-29 17:29:57 24 4
gpt4 key购买 nike

每次我通过 SSH 登录到我的服务器时,我需要键入以下内容:

export DJANGO_SETTINGS_MODULE=settings

如果我不这样做,manage.py 模块的任何使用都会失败

我的 manage.py 添加了以下代码:

if "notification" in settings.INSTALLED_APPS:
from notification import models as notification

def create_notice_types(app, created_models, verbosity, **kwargs):
notification.create_notice_type("friends_invite", _("Invitation Received"), _("you have received an invitation"))
notification.create_notice_type("friends_accept", _("Acceptance Received"), _("an invitation you sent has been accepted"))

signals.post_syncdb.connect(create_notice_types, sender=notification)
else:
print "Skipping creation of NoticeTypes as notification app not found"

有什么想法吗?

最佳答案

您的manage.py 正在引用一个应用程序(通知)。这迫使 Django 提示 DJANGO_SETTINGS_MODULE 被设置,因为 Django 环境尚未设置。

顺便说一下,您可以手动强制设置环境,但老实说我不会在 manage.py 中这样做。在我看来,这并不是一个好的做法。

以下是您可以在任何应用程序(或相关程序)中手动设置 Django 环境的方法:

# set up the environment using the settings module
from django.core.management import setup_environ
from myapp import settings
setup_environ(settings)

关于python - 为什么我需要 DJANGO_SETTINGS_MODULE 集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2102330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com