Permalink
Browse files

Fixes issue #280: don't attempt to import Django's AdminMediaHandler,…

… and ask the user to disable LETTUCE_SERVE_ADMIN_MEDIA on Django >=1.5
  • Loading branch information...
1 parent b83537c commit d4d215baa4373457e2615f4daf5963f6b7ff41b3 @akaihola akaihola committed Aug 2, 2012
Showing with 11 additions and 2 deletions.
  1. +11 −2 lettuce/django/server.py
View
@@ -31,7 +31,10 @@
from django.core.servers.basehttp import ServerHandler
from django.core.servers.basehttp import WSGIRequestHandler
from django.core.servers.basehttp import WSGIServerException
-from django.core.servers.basehttp import AdminMediaHandler
+try:
+ from django.core.servers.basehttp import AdminMediaHandler
+except ImportError:
+ AdminMediaHandler = None
try:
from django.contrib.staticfiles.handlers import StaticFilesHandler
except ImportError:
@@ -137,7 +140,8 @@ def should_serve_static_files(self):
def should_serve_admin_media(self):
try:
- return ('django.contrib.admin' in settings.INSTALLED_APPS or
+ return (('django.contrib.admin' in settings.INSTALLED_APPS and
+ AdminMediaHandler) or
getattr(settings, 'LETTUCE_SERVE_ADMIN_MEDIA', False))
except ImportError:
return False
@@ -181,6 +185,11 @@ def run(self):
handler = WSGIHandler()
if self.should_serve_admin_media():
+ if not AdminMediaHandler:
+ raise LettuceServerException(
+ "AdminMediaHandler is not available in this version of "
+ "Django. Please set LETTUCE_SERVE_ADMIN_MEDIA = False "
+ "in your Django settings.")
admin_media_path = ''
handler = AdminMediaHandler(handler, admin_media_path)

0 comments on commit d4d215b

Please sign in to comment.