Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

from optparse import make_option 

 

from django.conf import settings 

from django.core.management.commands.runserver import BaseRunserverCommand 

 

from django.contrib.staticfiles.handlers import StaticFilesHandler 

 

class Command(BaseRunserverCommand): 

    option_list = BaseRunserverCommand.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 and also serves static files." 

 

    def get_handler(self, *args, **options): 

        """ 

        Returns the static files serving handler wrapping the default handler, 

        if static files should be served. Otherwise just returns the default 

        handler. 

 

        """ 

        handler = super(Command, self).get_handler(*args, **options) 

        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): 

            return StaticFilesHandler(handler) 

        return handler