1👍
You need to set an OS environ value for DJANGO_SETTINGS_MODULE. You can do that with a simple EXPORT command. If you are using virtualenv, I hightly recommend virtualenvwrapper and I put this setting in the ‘bin/postactivate’ file.
Note: I just tested it via the django 1.4 shell and the import works fine for me.
0👍
Your manage.py
file defines DJANGO_SETTINGS_MODULE. Since your running this code outside of your django application, you need to define it yourself.
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", <location of settings.py>)
- [Answer]-Limit inlines to edit mode in Django's ModelAdmin
- [Answer]-Django render understanding context_instance
- [Answer]-Django template variable containing template tag, ex {{ {% some_tag %} }}
- [Answer]-Django while deleting entry getting error local variable 'delete' referenced before assignment
0👍
You have to set the environment variable DJANGO_SETTINGS_MODULE
. The easiest way to do it is to put the following code at the top of the file that contains your failing import statement:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'path/to/your/settings.py'
# ...
from django.db import connection
- [Answer]-DataError for a DateTime?
- [Answer]-Django and Python-Social-Auth redirect if I make custom pipeline
- [Answer]-Create template for forms django
- [Answer]-Django form field is not displayed
- [Answer]-Django: How to render form field by html_name
Source:stackexchange.com