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 4 years, 7 months ago
  2. FreeBSD rc.d FastCGI Script by davidblewett 4 years, 8 months ago
  3. Django with Fast CGI (Server Conf) by jackoder 3 years ago
  4. django under apache / mod_fcgid by mike_45 4 years, 3 months ago
  5. autotranslate po files using microsoft translator by prabhat246 1 year, 3 months ago

Comments

(Forgotten your password?)