Non-global middleware in Django

前端 未结 8 1003
生来不讨喜
生来不讨喜 2020-12-12 21:59

In Django there is a settings file that defines the middleware to be run on each request. This middleware setting is global. Is there a way to specify a set of middleware

8条回答
  •  粉色の甜心
    2020-12-12 22:45

    I think this is the easy way to exclude a view from middleware

     from django.core.urlresolvers import resolve
     current_url = resolve(request.path_info).url_name
    
     if want to exclude url A,
    
     class your_middleware:
        def process_request(request):
            if not current_url == 'A':
                "here add your code"
    

提交回复
热议问题