[Answer]-Can't import django.db.models from Python GUI

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

Leave a comment