Ticket #7930: dev_server__force_script_name.diff

File dev_server__force_script_name.diff, 1.2 KB (added by guettli, 7 years ago)
  • django/core/servers/basehttp.py

     
    557557        BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
    558558
    559559    def get_environ(self):
     560        from django.conf import settings
    560561        env = self.server.base_environ.copy()
    561562        env['SERVER_PROTOCOL'] = self.request_version
    562563        env['REQUEST_METHOD'] = self.command
     
    565566        else:
    566567            path,query = self.path,''
    567568
     569        if settings.FORCE_SCRIPT_NAME:
     570            prefix='%s/' % settings.FORCE_SCRIPT_NAME
     571            if path.startswith(prefix):
     572                # Remove FORCE_SCRIPT_NAME if path starts with this string.
     573                # This makes it possible to server dynamic content and static
     574                # (which would be outside of FORCE_SCRIPT_NAME).
     575                # Drawback: URLs like /scriptname/scriptname/ are not accessible.
     576                path=path[len(prefix)-1:]
     577
    568578        env['PATH_INFO'] = urllib.unquote(path)
    569579        env['QUERY_STRING'] = query
    570580        env['REMOTE_ADDR'] = self.client_address[0]
Back to Top