我正在编写自定义中间件,如果满足条件,我想重定向到另一个页面。我的代码如下所示:
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
如何重定向到所需的页面?