DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Standalone Django For Testing

  • submit to reddit
        // For running django directly rather than running it through a server.
// I use it for testing.

# Put this at the top of your module, before you import
# any of the django code. For an in-depth discussion, see
# James Bennett's blog -

if __name__=='__main__':
    # Path to my django project.
    import sys
    sys.path.insert(0,r'C:\Documents and Settings\CCM\Desktop\my_project')
    from import setup_environ    
    from my_projects import settings

# An example import. By adding the project path to sys.path, the imports
# do not have to include the project name (e.g. my_project.an_app.models),
# which makes it easy to insert this code in another project.
from an_app.models import AModel