Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

runserver_plus doesn't serve static files with staticfile app #124

Merged
merged 4 commits into from Aug 22, 2011
@@ -1,8 +1,14 @@
+from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from optparse import make_option
import os
import sys
+try:
+ from django.contrib.staticfiles.handlers import StaticFilesHandler
+ USE_STATICFILES = 'django.contrib.staticfiles' in settings.INSTALLED_APPS
+except ImportError, e:
+ USE_STATICFILES = False
def null_technical_500_response(request, exc_type, exc_value, tb):
raise exc_type, exc_value, tb
@@ -19,6 +25,13 @@ class Command(BaseCommand):
make_option('--threaded', action='store_true', dest='threaded',
help='Run in multithreaded mode.'),
)
+ if USE_STATICFILES:
+ option_list += (
+ make_option('--nostatic', action="store_false", dest='use_static_handler', default=True,
+ help='Tells Django to NOT automatically serve static files at STATIC_URL.'),
+ make_option('--insecure', action="store_true", dest='insecure_serving', default=False,
+ help='Allows serving static files even if DEBUG is False.'),
+ )
help = "Starts a lightweight Web server for development."
args = '[optional port number, or ipaddr:port]'
@@ -64,7 +77,6 @@ def handle(self, addrport='', *args, **options):
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
def inner_run():
- from django.conf import settings
print "Validating models..."
self.validate(display_num_errors=True)
print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
@@ -73,6 +85,11 @@ def inner_run():
print "Quit the server with %s." % quit_command
path = admin_media_path or django.__path__[0] + '/contrib/admin/media'
handler = AdminMediaHandler(WSGIHandler(), path)
+ if USE_STATICFILES:
+ use_static_handler = options.get('use_static_handler', True)
+ insecure_serving = options.get('insecure_serving', False)
+ if use_static_handler and (settings.DEBUG or insecure_serving) and 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
+ handler = StaticFilesHandler(handler)
if open_browser:
import webbrowser
url = "http://%s:%s/" % (addr, port)
View
@@ -15,3 +15,5 @@ Patrick Altman (paltman) - Patched sync_media_s3
Chris Beaven (smileychris) - widont filter
qMax - various graph_model patches
Tyson Clugg (tclugg) - Patched sqldiff
+Domen Kožar (iElectric) - staticfiles patch improvement
+quinox - original staticfiles patch