Django: How can I apply the login_required decorator to my entire site (excluding static media)?

前端 未结 10 2005
日久生厌
日久生厌 2020-12-24 07:21

The example provides a snippet for an application level view, but what if I have lots of different (and some non-application) entries in my \"urls.py\" file, including templ

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 08:01

    Use middleware.

    http://www.djangobook.com/en/2.0/chapter17/ and http://docs.djangoproject.com/en/1.2/topics/http/middleware/#topics-http-middleware

    I'm assuming this didn't change a whole lot in 1.2

    Middleware allows you to create a class with methods who will process every request at various times/conditions, as you define.

    for example process_request(request) would fire before your view, and you can force authentication and authorization at this point.

提交回复
热议问题