Code

Ticket #7930: dev_server__force_script_name.diff

File dev_server__force_script_name.diff, 1.2 KB (added by guettli, 6 years ago)
Line 
1Index: django/core/servers/basehttp.py
2===================================================================
3--- django/core/servers/basehttp.py     (Revision 9014)
4+++ django/core/servers/basehttp.py     (Arbeitskopie)
5@@ -557,6 +557,7 @@
6         BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
7 
8     def get_environ(self):
9+        from django.conf import settings
10         env = self.server.base_environ.copy()
11         env['SERVER_PROTOCOL'] = self.request_version
12         env['REQUEST_METHOD'] = self.command
13@@ -565,6 +566,15 @@
14         else:
15             path,query = self.path,''
16 
17+        if settings.FORCE_SCRIPT_NAME:
18+            prefix='%s/' % settings.FORCE_SCRIPT_NAME
19+            if path.startswith(prefix):
20+                # Remove FORCE_SCRIPT_NAME if path starts with this string.
21+                # This makes it possible to server dynamic content and static
22+                # (which would be outside of FORCE_SCRIPT_NAME).
23+                # Drawback: URLs like /scriptname/scriptname/ are not accessible.
24+                path=path[len(prefix)-1:]
25+
26         env['PATH_INFO'] = urllib.unquote(path)
27         env['QUERY_STRING'] = query
28         env['REMOTE_ADDR'] = self.client_address[0]