Run Django as a FastCGI authorizer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
import sys, os

# Set the DJANGO_SETTINGS_MODULE environment variable.
# Customise this for your setup
os.environ['DJANGO_SETTINGS_MODULE'] = "djsite.settings"

from django.core.handlers.wsgi import WSGIHandler
main_handler = WSGIHandler()

def wrapper(environ, start_response):
    """FastCGI Authorizers don't get PATH_INFO.  Make one from
    REQUEST_URI so that Django can use it in URL matching."""
    if not environ["PATH_INFO"]:
        # Fastcgi doesn't give you PATH_INFO for authorizers
        uri = environ['REQUEST_URI']
        if '?' in uri:
            path, query = environ['REQUEST_URI'].split('?', 1)
        else:
            path, query = uri, ''
        environ['PATH_INFO'] = path

    return main_handler(environ, start_response)

if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    from flup.server.fcgi_base import FCGI_AUTHORIZER

    # Django normally uses the FCGI_RESPONDER role and will reject AUTHORIZER
    # requests.
    WSGIServer(wrapper, roles=(FCGI_AUTHORIZER,)).run()

More like this

  1. Simple FastCGI authorizer view by cme 5 years, 6 months ago
  2. autotranslate po files using microsoft translator by prabhat246 2 years, 2 months ago
  3. Mobilize your Django site by stevena0 5 years ago
  4. Mod to allow simple_tag to access context by leaf 5 years, 6 months ago
  5. testdata tag for templates by showell 4 years, 11 months ago

Comments

(Forgotten your password?)