Over a million developers have joined DZone.

Standalone Django For Testing

DZone's Guide to

Standalone Django For Testing

Free Resource
// 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 - http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/

if __name__=='__main__':
    # Path to my django project.
    import sys
    sys.path.insert(0,r'C:\Documents and Settings\CCM\Desktop\my_project')
    from django.core.management 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

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}