From 62cc287b2b6466e877b2f46d9e0825fb294f542e Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 18 Jul 2005 22:49:04 +0000 Subject: [PATCH] Fixed #76 -- development server now serves images, too, at whatever relative URL is provided by ADMIN_MEDIA_PREFIX git-svn-id: http://code.djangoproject.com/svn/django/trunk@186 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/handlers/wsgi.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index 5006272685..9a4c719245 100644 --- a/django/core/handlers/wsgi.py +++ b/django/core/handlers/wsgi.py @@ -252,18 +252,21 @@ class AdminMediaHandler: from django.conf import settings import django self.application = application - self.media_dir = django.__path__[0] + '/conf/admin_templates' + self.media_dir = django.__path__[0] + '/conf/admin_media' self.media_url = settings.ADMIN_MEDIA_PREFIX def __call__(self, environ, start_response): import os.path - # Ignore requests that aren't under ADMIN_MEDIA_PREFIX. - if not environ['PATH_INFO'].startswith(self.media_url): + # Ignore requests that aren't under ADMIN_MEDIA_PREFIX. Also ignore + # all requests if ADMIN_MEDIA_PREFIX isn't a relative URL. + if self.media_url.startswith('http://') or self.media_url.startswith('https://') \ + or not environ['PATH_INFO'].startswith(self.media_url): return self.application(environ, start_response) # Find the admin file and serve it up, if it exists and is readable. - file_path = os.path.join(self.media_dir, environ['PATH_INFO'][1:]) + relative_url = environ['PATH_INFO'][len(self.media_url):] + file_path = os.path.join(self.media_dir, relative_url) if not os.path.exists(file_path): status = '404 NOT FOUND' headers = {'Content-type': 'text/plain'}