1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

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
This commit is contained in:
Adrian Holovaty 2005-07-18 22:49:04 +00:00
parent a7506973af
commit 62cc287b2b

View File

@ -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'}