Does django staticfiles skip the middleware?

后端 未结 2 964
自闭症患者
自闭症患者 2021-01-11 23:35

I\'m running a django 1.4.1 app.

I didn\'t realize that just including django.contrib.staticfiles into INSTALLED_APPS in your settings is e

相关标签:
2条回答
  • 2021-01-12 00:26

    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).

    0 讨论(0)
  • 2021-01-12 00:35

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

    Discovered urls resolve against request.path_info not request.path

    0 讨论(0)
提交回复
热议问题