1👍
✅
Not all of Django supports simply being loaded as a Python module, unfortunately; you need to use the means provided by Django itself to bootstrap the environment needed to load stuff like models.
One option is to use the Django shell but it’s also possible to use a purely programmatic solution from your own code. See https://docs.djangoproject.com/en/dev/topics/settings/ for all the options.
Here’s also an example by somebody else https://gist.github.com/jordanorelli/1025419 but I haven’t verified if it’s up to date.
0👍
The answer is in the error message:
You must either define the environment variable DJANGO_SETTINGS_MODULE or...
For this reason Django provides a shortcut to loading a python shell with Django settings configured:
https://docs.djangoproject.com/en/dev/ref/django-admin/#shell
- [Answer]-Django Multiple ForeignKey Navigation
- [Answer]-CMS for Django when upgrading app from 1.5.5 to 1.7.1
- [Answer]-How to output django_filters.RangeFilter text boxes inline?
- [Answer]-How to save JSON from Vk.com API response to MongoDB?
Source:stackexchange.com