Tuesday, January 31, 2012

Python & Django - Playing with the API

Playing with the API

Now, let's hop into the interactive Python shell and play around with the free API Django gives you. To invoke the Python shell, use this command:
python manage.py shell
We're using this instead of simply typing "python", because manage.py sets up the project's environment for you. "Setting up the environment" involves two things:
  • Putting polls on sys.path. For flexibility, several pieces of Django refer to projects in Python dotted-path notation (e.g. 'polls.models'). In order for this to work, the polls package has to be onsys.path.
    We've already seen one example of this: the INSTALLED_APPS setting is a list of packages in dotted-path notation.
  • Setting the DJANGO_SETTINGS_MODULE environment variable, which gives Django the path to yoursettings.py file.

No comments: