paulb@557 | 1 | NOTE: The following examples do not currently work with Django: Auth, Calendar.
|
paulb@557 | 2 |
|
paulb@557 | 3 | WebStack supports Django in the sense that WebStack applications can be
|
paulb@557 | 4 | deployed within Django instances according to the guidelines described in the
|
paulb@557 | 5 | Django documentation plus a few caveats. Here is the basic process:
|
paulb@557 | 6 |
|
paulb@557 | 7 | 1. Create a Django instance or find an existing instance to use.
|
paulb@557 | 8 | 2. Create or find an application where WebStack resources and applications
|
paulb@557 | 9 | shall be deployed.
|
paulb@557 | 10 | 3. Add URL mappings to the instance's urls.py file - see below for a
|
paulb@557 | 11 | description of how this should be done.
|
paulb@557 | 12 | 4. Add WebStack handlers to the application directory.
|
paulb@575 | 13 | 5. Add the application to the INSTALLED_APPS definition in the settings.py
|
paulb@575 | 14 | file.
|
paulb@575 | 15 | 6. Configure Django in mod_python.
|
paulb@557 | 16 |
|
paulb@575 | 17 | Create a Django instance
|
paulb@575 | 18 | ------------------------
|
paulb@575 | 19 |
|
paulb@575 | 20 | For example:
|
paulb@575 | 21 |
|
paulb@575 | 22 | django-admin.py startproject djangoinstance
|
paulb@575 | 23 |
|
paulb@575 | 24 | Create an application
|
paulb@575 | 25 | ---------------------
|
paulb@575 | 26 |
|
paulb@575 | 27 | For example:
|
paulb@575 | 28 |
|
paulb@575 | 29 | cd djangoinstance
|
paulb@575 | 30 | mkdir webstack
|
paulb@575 | 31 |
|
paulb@575 | 32 | Add URL mappings
|
paulb@575 | 33 | ----------------
|
paulb@557 | 34 |
|
paulb@557 | 35 | The docs/Django/urls.py file contains definitions for the example applications
|
paulb@557 | 36 | based on a Django instance called "djangoinstance" (in a directory of that
|
paulb@557 | 37 | name) and the "webstack" application (in a directory of that name within the
|
paulb@557 | 38 | instance). The urls.py file employs URL patterns to direct requests to each of
|
paulb@557 | 39 | the examples.
|
paulb@557 | 40 |
|
paulb@557 | 41 | Consider the auth example - the following pattern is employed to detect
|
paulb@557 | 42 | requests intended for it:
|
paulb@557 | 43 |
|
paulb@557 | 44 | ^django/webstack/auth(?P<vp>/.*)?
|
paulb@557 | 45 |
|
paulb@557 | 46 | Here, the example will be accessible via a URL like this:
|
paulb@557 | 47 |
|
paulb@557 | 48 | http://localhost/django/webstack/auth
|
paulb@557 | 49 |
|
paulb@557 | 50 | Additional path information is captured by a special named regular expression
|
paulb@557 | 51 | group which is used within the WebStack adapter.
|
paulb@557 | 52 |
|
paulb@557 | 53 | WebStack handlers and adapters
|
paulb@557 | 54 | ------------------------------
|
paulb@557 | 55 |
|
paulb@557 | 56 | The handlers from examples/Django should be copied into or otherwise linked to
|
paulb@557 | 57 | from the "webstack" application directory within the Django instance. Each
|
paulb@557 | 58 | handler should contain a function, produced by calling the special deploy
|
paulb@557 | 59 | function from the Django adapter, with a name as stated in the urls.py file.
|
paulb@557 | 60 |
|
paulb@557 | 61 | Consider the auth example - the following path to the resource is stated:
|
paulb@557 | 62 |
|
paulb@557 | 63 | djangoinstance.webstack.authapp.auth
|
paulb@557 | 64 |
|
paulb@557 | 65 | Here, within the instance and application, the "authapp" handler (provided by
|
paulb@557 | 66 | the authapp.py from examples/Django) must contain a function called "auth".
|
paulb@575 | 67 |
|
paulb@575 | 68 | Add the application to the settings
|
paulb@575 | 69 | -----------------------------------
|
paulb@575 | 70 |
|
paulb@575 | 71 | For example:
|
paulb@575 | 72 |
|
paulb@575 | 73 | INSTALLED_APPS = (
|
paulb@575 | 74 | 'django.contrib.auth',
|
paulb@575 | 75 | 'django.contrib.contenttypes',
|
paulb@575 | 76 | 'django.contrib.sessions',
|
paulb@575 | 77 | 'django.contrib.sites',
|
paulb@575 | 78 | 'djangoinstance.webstack', # Application added here!
|
paulb@575 | 79 | )
|
paulb@575 | 80 |
|
paulb@575 | 81 | Django and mod_python
|
paulb@575 | 82 | ---------------------
|
paulb@575 | 83 |
|
paulb@575 | 84 | For example:
|
paulb@575 | 85 |
|
paulb@575 | 86 | <Location "/django/">
|
paulb@575 | 87 | SetHandler python-program
|
paulb@575 | 88 | PythonHandler django.core.handlers.modpython
|
paulb@575 | 89 | SetEnv DJANGO_SETTINGS_MODULE djangoinstance.settings
|
paulb@575 | 90 | PythonDebug On
|
paulb@575 | 91 | PythonPath "['/home/paulb/Software/Python', '/home/paulb/Software/Python/WebStack', '/home/paulb/Software/Python/WebStack/examples/Common'] + sys.path"
|
paulb@575 | 92 | </Location>
|