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.

static.py 844B

123456789101112131415161718192021222324252627
  1. import re
  2. from django.conf import settings
  3. from django.core.exceptions import ImproperlyConfigured
  4. from django.urls import re_path
  5. from django.views.static import serve
  6. def static(prefix, view=serve, **kwargs):
  7. """
  8. Return a URL pattern for serving files in debug mode.
  9. from django.conf import settings
  10. from django.conf.urls.static import static
  11. urlpatterns = [
  12. # ... the rest of your URLconf goes here ...
  13. ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  14. """
  15. if not prefix:
  16. raise ImproperlyConfigured("Empty static prefix not permitted")
  17. elif not settings.DEBUG or '://' in prefix:
  18. # No-op if not in debug mode or a non-local prefix.
  19. return []
  20. return [
  21. re_path(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
  22. ]