1 | """
|
---|
2 | prereqs:
|
---|
3 | 1) add autoreload.py to django/utils folder
|
---|
4 | 2) create scripts folder (sibling to 'apps' and 'settings')
|
---|
5 | 3) store this file in <yourproject>/scripts/
|
---|
6 | 4) 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?
|
---|
16 | DJANGO_SETTINGS_MODULE = '<change_me_to_the_name_of_your_app>.settings.admin'
|
---|
17 | PORT = '<change_me_to_the_port_you_want_to_run_django_on>' #must be a string
|
---|
18 |
|
---|
19 |
|
---|
20 | def 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 |
|
---|
40 | if __name__ == "__main__":
|
---|
41 | from django.utils import autoreload
|
---|
42 | autoreload.main(start)
|
---|