为什么我需要设置DJANGO_SETTINGS_MODULE? [英] Why do I need the DJANGO_SETTINGS_MODULE set?
问题描述
每次通过SSH登录我的服务器时,我需要键入以下内容:
Every time I log on to my server through SSH I need to type the following:
export DJANGO_SETTINGS_MODULE=settings
如果我没有使用manage.py模块失败
if I do not any usage of the manage.py module fails
我的manage.py有以下添加的代码:
My manage.py has the following added code:
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
正在引用一个应用程序( notifications
)。由于Django环境尚未设置,Django会抱怨DJANGO_SETTINGS_MODULE被设置。
Yourmanage.py
is referencing an application (notifications
). This forces Django to complain about DJANGO_SETTINGS_MODULE being set because the Django environment hasn't been set up yet.
顺便说一下,您可以手动强制环境设置,但是老实说,我会不要在manage.py中执行此操作。这在我看来并不是一个很好的做法。
Incidentally, you can force the enviroment setup manually, but honestly I wouldn't do this in manage.py. That's not really a good practice in my opinion.
以下是您可以从任何应用程序(或程序中)手动设置Django环境:
Here is how you can manually setup the Django environment from within any app (or program for that matter):
# set up the environment using the settings module
from django.core.management import setup_environ
from myapp import settings
setup_environ(settings)
这篇关于为什么我需要设置DJANGO_SETTINGS_MODULE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!