Code

Ticket #4891: modpython.diff

File modpython.diff, 1.8 KB (added by Thomas Güttler <hv@…>, 7 years ago)
Line 
1Index: docs/modpython.txt
2===================================================================
3--- docs/modpython.txt  (Revision 5718)
4+++ docs/modpython.txt  (Arbeitskopie)
5@@ -78,10 +78,14 @@
6 You can also add directives such as ``PythonAutoReload Off`` for performance.
7 See the `mod_python documentation`_ for a full list of options.
8 
9-Note that you should set ``PythonDebug Off`` on a production server. If you
10-leave ``PythonDebug On``, your users would see ugly (and revealing) Python
11-tracebacks if something goes wrong within mod_python.
12+Note that you should set ``PythonDebug Off`` on a production
13+server. If you leave ``PythonDebug On``, your users would see ugly
14+(and revealing) Python tracebacks if something goes wrong within
15+mod_python. For debugging errors on mod_python level, you can switch
16+on cgitb by using::
17 
18+        PythonHandler django.core.handlers.modpython::handler_cgitb
19+
20 Restart Apache, and any request to /mysite/ or below will be served by Django.
21 Note that Django's URLconfs won't trim the "/mysite/" -- they get passed the
22 full URL.
23Index: django/core/handlers/modpython.py
24===================================================================
25--- django/core/handlers/modpython.py   (Revision 5718)
26+++ django/core/handlers/modpython.py   (Arbeitskopie)
27@@ -174,5 +174,23 @@
28         return 0 # mod_python.apache.OK
29 
30 def handler(req):
31+    """
32+    Default Handler:
33+    PythonHandler django.core.handlers.modpython
34+    """
35     # mod_python hooks into this function.
36     return ModPythonHandler()(req)
37+
38+def handler_cgitb(req):
39+    """
40+    CGI Trackback Handler:
41+    PythonHandler django.core.handlers.modpython::handler_cgitb
42+    """
43+    import cgitb
44+    try:
45+        handler(req)
46+    except:
47+        req.content_type = 'text/html'
48+        cgitb.Hook(file = req).handle()
49+    return 0 # mod_python.apache.OK
50+