Answer the question
In order to leave comments, you need to log in
Django: loading settings.py from applications
In general, what's the matter. There is a site, inside the standard files, and the apps folder in which, respectively, the applications are located, for example, the twitter application. Inside the twitter folder there is a script that, in theory, needs to be run periodically not from Django itself, but by the scheduler to edit the database. To edit the database inside the script, the file with the model is accordingly imported.
In general, if you run this file from Eclipce with PyDev, everything works fine. But if you try to run it just by clicking the mouse, I stumble upon the error of the absence of the settings. I feel Eclipce feeds everything to him at startup, but how to manually run it?
Answer the question
In order to leave comments, you need to log in
Either write your own command for manage.py, or define the DJANGO_SETTINGS_MODULE environment variable, something like
import os, sys
sys.path.append('c:\path\to\project')
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
from my_app.models import blablabla
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question