【发布时间】:2011-10-16 00:53:59
【问题描述】:
我尝试在 Django 中编写自定义装饰器。 如果用户未通过该页面登录,我想将用户重定向到自定义登录页面。 我已经编写了装饰器并对其进行了调试。虽然如果用户没有登录它工作得很好,但在用户登录后它会给出错误
The view APPNAME.views.home didn't return an HttpResponse object.
您可以在下面找到我的代码。为什么我的装饰器在私有 alfa 页面中进行身份验证后直接跳转到 return wraps(func)(inner_decorator) 部分?
谢谢
def private_alfa_required():
def decorator(func):
def inner_decorator(request,*args, **kwargs):
if 'isPrivateAlfaUser' not in request.session or request.session['isPrivateAlfaUser'] != True:
return render_to_response('homepage.html')
return wraps(func)(inner_decorator)
return decorator
@private_alfa_required()
def home(request):
.....
def home2(request):
.....
【问题讨论】: