PageRenderTime 72ms CodeModel.GetById 41ms app.highlight 3ms RepoModel.GetById 27ms app.codeStats 0ms

/django/contrib/staticfiles/management/commands/runserver.py

https://code.google.com/p/mango-py/
Python | 27 lines | 20 code | 4 blank | 3 comment | 3 complexity | 899a8105e90ba7a7910a871336f11aba MD5 | raw file
 1from optparse import make_option
 2
 3from django.conf import settings
 4from django.core.management.commands.runserver import BaseRunserverCommand
 5
 6from django.contrib.staticfiles.handlers import StaticFilesHandler
 7
 8class Command(BaseRunserverCommand):
 9    option_list = BaseRunserverCommand.option_list + (
10        make_option('--nostatic', action="store_false", dest='use_static_handler', default=True,
11            help='Tells Django to NOT automatically serve static files at STATIC_URL.'),
12        make_option('--insecure', action="store_true", dest='insecure_serving', default=False,
13            help='Allows serving static files even if DEBUG is False.'),
14    )
15    help = "Starts a lightweight Web server for development and also serves static files."
16
17    def get_handler(self, *args, **options):
18        """
19        Returns the static files serving handler.
20        """
21        handler = super(Command, self).get_handler(*args, **options)
22        use_static_handler = options.get('use_static_handler', True)
23        insecure_serving = options.get('insecure_serving', False)
24        if (settings.DEBUG and use_static_handler or
25                (use_static_handler and insecure_serving)):
26            handler = StaticFilesHandler(handler)
27        return handler