Posted By

dorseye on 10/16/09


python django interpreter

Versions (?)

Django interactive interpreter

 / Published in: Python


A special Python prompt

If you’ve used Python before, you may be wondering why we’re running python shell instead of just python. Both commands will start the interactive interpreter, but the 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 For example, DJANGOSETTINGSMODULE might be set to 'mysite.settings', assuming mysite is on your Python path.

When you run python shell, the command takes care of setting DJANGOSETTINGSMODULE for you. We’re encouraging you to use python 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 shell and will set DJANGOSETTINGSMODULE manually in your .bash_profile or other shell environment configuration file.

  1. python shell

Report this snippet  

You need to login to post a comment.