S
S
S0ulReaver2012-01-29 17:53:46
Django
S0ulReaver, 2012-01-29 17:53:46

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

2 answer(s)
P
Pavel Zagrebelin, 2012-01-29
@Zagrebelion

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

R
Riateche, 2012-01-29
@Riateche

For example, like this: cat path_to_script | ./manage.py shell
Run in the folder that contains manage.py.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question