A special Python prompt
If you’ve used Python before, you may be wondering why we’re running python manage.py shell instead of just python. Both commands will start the interactive interpreter, but the manage.py shell command has one key difference: before starting the interpreter, it tells Django which settings file to use. Many parts of Django, including the template system, rely on your settings, and you won’t be able to use them unless the framework knows which settings to use.
If you’re curious, here’s how it works behind the scenes. Django looks for an environment variable called DJANGOSETTINGSMODULE, which should be set to the import path of your settings.py. For example, DJANGOSETTINGSMODULE might be set to 'mysite.settings', assuming mysite is on your Python path.
When you run python manage.py shell, the command takes care of setting DJANGOSETTINGSMODULE for you. We’re encouraging you to use python manage.py shell in these examples so as to minimize the amount of tweaking and configuring you have to do.
As you become more familiar with Django, you’ll likely stop using manage.py shell and will set DJANGOSETTINGSMODULE manually in your .bash_profile or other shell environment configuration file.
You need to login to post a comment.