Using the Django shell

With the virtual environment activated and your project directory selected as the current directory, enter the following command in your command-line tool:

(myproject_env)$ python manage shell

By executing the preceding command, you will get in an interactive Python shell configured for your Django project, where you can play around with the code, inspect classes, try out methods, or execute scripts on the fly. In this recipe, we will go through the most important functions that you need to know in order to work with the Django shell.

Getting ready

You can either install IPython or bpython using one of the following commands, which will highlight the syntax for the output of your Django shell and add some other helpers:

Get Web Development with Django Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.