2
I am doing some tests in a Django project. I created a very simple module just for testing. Below:
from django.contrib.auth.models import User
def teste():
for i in User.objects.all():
print i.username
if __name__ == "__main__":
teste()
When executing the code, this error is returned:
Traceback (Most recent call last): File "test.py", line 6, in from Django.contrib.auth.models import User File "/home/carlos/myworkspace/Helpdesk/lib/python2.7/site-Packages/Django /contrib/auth/init.py", line 6, in from Django.middleware.csrf import rotate_token File "/home/carlos/myworkspace/Helpdesk/lib/python2.7/site-Packages/Django /middleware/csrf.py", line 14, in from Django.utils.cache import patch_vary_headers File "/home/carlos/myworkspace/Helpdesk/lib/python2.7/site-Packages/Django/utils/cache.py", line 26, in from Django.core.cache import get_cache File "/home/carlos/myworkspace/Helpdesk/lib/python2.7/site-Packages/Django/core/cache/init.py", line 69, in if DEFAULT_CACHE_ALIAS not in Settings.CACHES: File "/home/carlos/myworkspace/Helpdesk/lib/python2.7/site-Packages/Django/conf/init.py", line 54, in getattr self. _setup(name) File "/home/carlos/myworkspace/Helpdesk/lib/python2.7/site-Packages/Django/conf/init.py", line 47, in _setup % (desc, ENVIRONMENT_VARIABLE)) Django.core.exceptions.Improperlyconfigured: Requested Setting CACHES, but Settings are not configured. You must either define the Environment variable DJANGO_SETTINGS_MODULE or call Settings.configure() before accessing Settings.
NOTE: Inside the python manage.py shell with the %run test.py command, the code works.
Now this returning : Import: Could not import Settings 'help.Settings' (Is it on sys.path? Is there an import error in the Settings file?): No module named help.Settings
– Welington Carlos
my path /home/carlos/myworkspace/Helpdesk/help/ /home/carlos/myworkspace/Helpdesk /home/carlos/myworkspace/Helpdesk/lib/python27.zip /home/carlos/myworkspace/Helpdesk/lib64/python2.7 /home/carlos/myworkspace/Helpdesk/lib64/python2.7 /home/carlos/myworkspace/Helpdesk/lib64/python2.7/lib-old /home/carlos/myworkspace/Helpdesk/lib64/python2.7/lib-dynload /usr/lib64/python2.7 /usr/lib/python2.7 ...
– Welington Carlos
meu wsgi : 
import os
import sys

sys.path.append('/home/carlos/myworkspace/helpdesk/help')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "help.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
– Welington Carlos
"help" is the name of the app or project? Have you tried with "Helpdesk.Settings" instead of "help.Settings"? Another option is to set DJANGO_SETTINGS_MODULE as an environment variable, like this:
export DJANGO_SETTINGS_MODULE="help.settings"– Michael Siegwarth
"help" is the name of the app and "Helpdesk" is from the project. The Settings file is in the "help" folder. $DJANGO_SETTINGS_MODULE and $PYTHONPATH are right. I am already two days researching and testing and nothing. I will continue and anything put. Thank you Michael.
– Welington Carlos
Ok. Just make sure to use "Helpdesk.Settings" then. The correct thing is to always use the name of the site/project, not the app.
– Michael Siegwarth
If the app is "help", the file
settings.pyshouldn’t be in the folderhelpbut in the briefcasehelpdesk(the project folder, along with theurls.pymaster and thewsgi.py) (Settings is from the entire site, not from the app and so onhelpdesk.settingsfunctionary)– laurent