[Solved]-Does django staticfiles skip the middleware?

15👍

I just figured this out after posting…

If you’re using django-admin.py runserver or python manage.py runserver, then it does some extra magic to add a staticfiles handler that your regular middleware can’t touch.

You can disable this by running django-admin.py runserver --nostatic — see the django docs

And when you do --nostatic it will fall back to the urls in your app, such as if you include staticfiles_urls() directly with:

urlpatterns += staticfiles_urlpatterns()

then your middleware will run for those urls (and of course all your others).

1👍

Found this issue when trying to modify request.path with middleware.

Discovered urls resolve against request.path_info not request.path

👤Doug

Leave a comment