Does django staticfiles skip the middleware?

后端 未结 2 963
自闭症患者
自闭症患者 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).

提交回复
热议问题