Skip to content

Commit

Permalink
Add StaticFilesHandler to be compatible with Django 1.3 staticfiles app
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Aug 7, 2011
1 parent f278a9d commit f97729b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions django_extensions/management/commands/runserver_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import os
import sys

try:
from django.contrib.staticfiles.handlers import StaticFilesHandler
except ImportError, e:
StaticFilesHandler = None

def null_technical_500_response(request, exc_type, exc_value, tb):
raise exc_type, exc_value, tb
Expand All @@ -19,6 +23,13 @@ class Command(BaseCommand):
make_option('--threaded', action='store_true', dest='threaded',
help='Run in multithreaded mode.'),
)
if StaticFilesHandler is not None:
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 @@ -73,6 +84,12 @@ 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 StaticFilesHandler is not None:
use_static_handler = options.get('use_static_handler', True)
insecure_serving = options.get('insecure_serving', False)
if (settings.DEBUG and use_static_handler or
(use_static_handler and insecure_serving)):
handler = StaticFilesHandler(handler)
if open_browser:
import webbrowser
url = "http://%s:%s/" % (addr, port)
Expand Down

0 comments on commit f97729b

Please sign in to comment.