我正在編寫自定義middlware,如果滿足條件,我想重定向到另一個頁面。我的代碼如下所示:django中間件重定向不呈現頁面
class SettingHandler(object):
def process_view(self, request, view_func, view_args, view_kwargs):
if request.user.paid:
return view_func(request, *view_args, **view_kwargs)
else:
return HttpResponseRedirect(reverse('setting'))
我的urls.py看起來是這樣的:
url(r'^setting/$', 'customers.settings', name='setting'),
當到達了重定向狀態時,頁面不呈現。控制檯中的輸出如下所示:
"GET /setting/ HTTP/1.1" 302 0
"GET /setting/ HTTP/1.1" 302 0
"GET /setting/ HTTP/1.1" 302 0
"GET /setting/ HTTP/1.1" 302 0
"GET /setting/ HTTP/1.1" 302 0
"GET /setting/ HTTP/1.1" 302 0
"GET /setting/ HTTP/1.1" 302 0
"GET /setting/ HTTP/1.1" 302 0
"GET /setting/ HTTP/1.1" 302 0
如何重定向到所需的頁面?
你可以顯示你的'urls.py'? – alecxe
我添加了我的urls.py – Atma