Using the Django shell
The Django shell is a powerful tool to add to any toolbox. It will activate the Python interactive interpreter and uses the Django database abstraction API to let us connect directly to the database(s) configured in a project. With this, we can write Python and perform queries directly from a terminal or command-line window.
To activate the Django shell, follow these steps:
- Open your terminal or command-line window and navigate to the root of your project. Make sure your virtual environment has been activated and then execute the following command:
(virtual_env) PS > python3 manage.py shell
- You should see it print out the following information about the
InteractiveConsole
that was launched:Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>>
- Your console...