Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

runserver.py 1.3KB

1234567891011121314151617181920212223242526272829303132
  1. from django.conf import settings
  2. from django.contrib.staticfiles.handlers import StaticFilesHandler
  3. from django.core.management.commands.runserver import (
  4. Command as RunserverCommand,
  5. )
  6. class Command(RunserverCommand):
  7. help = "Starts a lightweight Web server for development and also serves static files."
  8. def add_arguments(self, parser):
  9. super().add_arguments(parser)
  10. parser.add_argument(
  11. '--nostatic', action="store_false", dest='use_static_handler',
  12. help='Tells Django to NOT automatically serve static files at STATIC_URL.',
  13. )
  14. parser.add_argument(
  15. '--insecure', action="store_true", dest='insecure_serving',
  16. help='Allows serving static files even if DEBUG is False.',
  17. )
  18. def get_handler(self, *args, **options):
  19. """
  20. Return the static files serving handler wrapping the default handler,
  21. if static files should be served. Otherwise return the default handler.
  22. """
  23. handler = super().get_handler(*args, **options)
  24. use_static_handler = options['use_static_handler']
  25. insecure_serving = options['insecure_serving']
  26. if use_static_handler and (settings.DEBUG or insecure_serving):
  27. return StaticFilesHandler(handler)
  28. return handler