Ticket #113: server.py

File server.py, 1.4 KB (added by Jason Huggins, 19 years ago)

This should be stored in <yourapp>/scripts/ (see inline comments in the .py file for more info)

Line 
1"""
2prereqs:
31) add autoreload.py to django/utils folder
42) create scripts folder (sibling to 'apps' and 'settings')
53) store this file in <yourproject>/scripts/
64) from console, run: python server.py
7"""
8
9# Warning:
10# This works for me, but might not for you. (Windows XP, Python 2.4.1)
11
12# TODO: needs to be refactored to play nicer with the DJANGO_SETTINGS_MODULE and PORT command line arguments of django-admin
13
14# important configuration settings:
15#factor this into a meta config file?
16DJANGO_SETTINGS_MODULE = '<change_me_to_the_name_of_your_app>.settings.admin'
17PORT = '<change_me_to_the_port_you_want_to_run_django_on>' #must be a string
18
19
20def start():
21 import sys
22
23 #import the root of your application
24 #to get these relative paths correct, this script expects to be run from <yourproject>.scripts
25 sys.path.append('../../')
26
27 #The following is ugly... only because a hypenn makes "from django.bin.django-admin import runserver" invalid syntax.
28 import django
29 django_admin = __import__('django.bin.django-admin')
30 runserver = django.bin.__dict__['django-admin'].runserver
31
32
33 import os
34 os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE
35
36 #actually start things up...
37 runserver(PORT)
38
39
40if __name__ == "__main__":
41 from django.utils import autoreload
42 autoreload.main(start)
Back to Top