Skip to content

Commit

Permalink
Merge pull request #124 from iElectric/master
Browse files Browse the repository at this point in the history
Added staticfiles support to runserver_plus command.
  • Loading branch information
jezdez committed Aug 22, 2011
2 parents f278a9d + 946720b commit ffa0513
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 18 additions & 1 deletion django_extensions/management/commands/runserver_plus.py
@@ -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
Expand All @@ -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]'

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docs/AUTHORS
Expand Up @@ -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

0 comments on commit ffa0513

Please sign in to comment.