Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need the DJANGO_SETTINGS_MODULE set?

Tags:

python

django

Every time I log on to my server through SSH I need to type the following:

export DJANGO_SETTINGS_MODULE=settings

if I do not any usage of the manage.py module fails

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"

Any ideas?

like image 872
RadiantHex Avatar asked Jan 20 '10 15:01

RadiantHex


1 Answers

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.

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.

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)
like image 144
jathanism Avatar answered Oct 12 '22 04:10

jathanism