MCPcopy Create free account
hub / github.com/vercel/vercel / _wrap_django_static

Function _wrap_django_static

python/vercel-runtime/src/vercel_runtime/dev.py:432–454  ·  view source on GitHub ↗
(app: WSGIApplication)

Source from the content-addressed store, hash-verified

430
431
432def _wrap_django_static(app: WSGIApplication) -> WSGIApplication:
433 # Wrap the Django WSGI app with StaticFilesHandler so that requests to
434 # STATIC_URL are served from source directories via Django's staticfiles
435 # finders, without needing collectstatic to have been run.
436 try:
437 from django.conf import ( # noqa: PLC0415 # pyright: ignore[reportMissingImports, reportMissingTypeStubs]
438 settings as django_settings, # pyright: ignore[reportUnknownVariableType, reportMissingTypeStubs]
439 )
440
441 installed = getattr(django_settings, "INSTALLED_APPS", []) # pyright: ignore[reportUnknownArgumentType]
442 if "django.contrib.staticfiles" not in installed:
443 return app
444
445 from django.contrib.staticfiles.handlers import ( # noqa: PLC0415 # pyright: ignore[reportMissingImports, reportMissingTypeStubs]
446 StaticFilesHandler, # pyright: ignore[reportUnknownVariableType]
447 )
448
449 if result := _handle_manifest(app):
450 return result
451
452 return cast("WSGIApplication", StaticFilesHandler(app))
453 except ImportError:
454 return app
455
456
457def _handle_manifest(app: WSGIApplication) -> WSGIApplication | None:

Callers 1

_setup_appsFunction · 0.85

Calls 1

_handle_manifestFunction · 0.85

Tested by

no test coverage detected