[英]django middleware redirect infinite loop
我有一個中間件,可以檢查會話值並根據該值重定向。 我的問題是,它正在創建一個無限重定向循環,但我不確定為什么。
因此,我要檢查的是可見會話的值是否為yes,否則將用戶重定向到我的測試視圖。
這是我的中間件:
class CheckStatus(object):
def process_request(self, request):
if request.user.is_authenticated():
s = request.session.get('visible')
if str(s) is not 'yes':
return HttpResponseRedirect(reverse("myapp.myview.views.test"))
提供某些媒體文件時,至少應避免使其運行:
from django.conf import settings
class CheckStatus(object):
def process_request(self, request):
if request.user.is_authenticated():
if not request.path.startswith(settings.MEDIA_URL):
s = request.session.get('visible')
if str(s) is not 'yes':
return HttpResponseRedirect(reverse("myapp.myview.views.test"))
但是,更為下降的方法似乎是使用process_view
-method !
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.