我喜欢django的@login_required装饰器,但是有一件事我不知道该怎么做。
如果一个未经认证的用户试图访问一个私有页面(例如“/ @login_required -stuff/”),我想把他们踢回主页(例如"/ home /")。但我不想将"?next=“参数附加到url。换句话说,我只想重定向到"/home/",而不是"/home/?next=/private-stuff/“。
我该怎么做呢?有没有比仅仅编写自己的装饰器更好的方法呢?
发布于 2012-10-07 06:35:21
这不就是简单的:
@decorators.login_required(redirect_field_name=None)
发布于 2014-06-02 00:29:58
login(request, user)
if request.POST['next']:
return redirect(request.POST['next'])
else:
msg = u"Welcome..."
return render_to_response('members/welcome.html', {'msg':msg},
context_instance=RequestContext(request))
https://stackoverflow.com/questions/10950409
复制相似问题