mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #16050 -- BACKWARDS-INCOMPATIBLE CHANGE: Moved static files of the admin to conventional file system location.
This also removes the need for ADMIN_MEDIA_PREFIX and replaces it with the convention to find admin's static files at STATIC_URL + 'admin/'. Thanks to Jacob for the review and general help. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16487 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -12,6 +12,7 @@ import socket
|
||||
import sys
|
||||
import traceback
|
||||
import urllib
|
||||
import urlparse
|
||||
from SocketServer import ThreadingMixIn
|
||||
from wsgiref import simple_server
|
||||
from wsgiref.util import FileWrapper # for backwards compatibility
|
||||
@@ -91,7 +92,7 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from django.conf import settings
|
||||
self.admin_media_prefix = settings.ADMIN_MEDIA_PREFIX
|
||||
self.admin_media_prefix = urlparse.urljoin(settings.STATIC_URL, 'admin/')
|
||||
# We set self.path to avoid crashes in log_message() on unsupported
|
||||
# requests (like "OPTIONS").
|
||||
self.path = ''
|
||||
@@ -163,22 +164,18 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
|
||||
class AdminMediaHandler(handlers.StaticFilesHandler):
|
||||
"""
|
||||
WSGI middleware that intercepts calls to the admin media directory, as
|
||||
defined by the ADMIN_MEDIA_PREFIX setting, and serves those images.
|
||||
defined by the STATIC_URL setting, and serves those images.
|
||||
Use this ONLY LOCALLY, for development! This hasn't been tested for
|
||||
security and is not super efficient.
|
||||
|
||||
This is pending for deprecation since 1.3.
|
||||
"""
|
||||
def get_base_dir(self):
|
||||
return os.path.join(django.__path__[0], 'contrib', 'admin', 'media')
|
||||
return os.path.join(django.__path__[0], 'contrib', 'admin', 'static', 'admin')
|
||||
|
||||
def get_base_url(self):
|
||||
from django.conf import settings
|
||||
if not settings.ADMIN_MEDIA_PREFIX:
|
||||
raise ImproperlyConfigured(
|
||||
"The ADMIN_MEDIA_PREFIX setting can't be empty "
|
||||
"when using the AdminMediaHandler, e.g. with runserver.")
|
||||
return settings.ADMIN_MEDIA_PREFIX
|
||||
return urlparse.urljoin(settings.STATIC_URL, 'admin/')
|
||||
|
||||
def file_path(self, url):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user