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