Django CORS on static asset Django CORS on static asset django django

Django CORS on static asset


I'm assuming you're using the built-in staticfiles app to serve your static files in development. When using the runserver managment command along with staticfiles, it uses a WSGI handler to serve static files that bypasses middleware. (Django docs)

You can disable this by running python manage.py runserver --nostatic. When you use --nostatic it will handle static URLs the same as all other URLs, through your Django urlconf, so don't forget to include the staticfiles URLs in your root urlconf like so: (see Static file development view)

if settings.DEBUG:    from django.contrib.staticfiles.urls import staticfiles_urlpatterns    urlpatterns += staticfiles_urlpatterns()