Let’s say, for example, that you want to manually add certain objects without using the admin, or need to quickly check a function without creating unit tests for it. In that case, you will need to run Django-specific commands from a python shell.
import django or use
django-admin.py shell, you will probably hit the following error:
Error: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
The easiest way to circumvent this is to use the following command to open a Django shell:
python manage.py shell
This will automatically handle the settings module for you, and start a fresh shell from which you can create models, run functions and quickly test views.