我有一个输入字段<input type="hidden" name="next" value="{{ next }}" />
,但它不会用GET参数的值替换{{ next }}
。我找不到如何替换该值。
我的看法
class LoginView(FormView):
form_class = AuthenticationForm
redirect_field_name = REDIRECT_FIELD_NAME
template_name = 'user/login.html'
@method_decorator(csrf_protect)
@method_decorator(never_cache)
def dispatch(self, *args, **kwargs):
return super(LoginView, self).dispatch(*args, **kwargs)
def form_valid(self, form):
login(self.request, form.get_user())
return super(LoginView, self).form_valid(form)
def get_success_url(self):
if self.success_url:
redirect_to = self.success_url
else:
redirect_to = self.request.REQUEST.get(self.redirect_field_name, '')
if not redirect_to:
redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
return redirect_to
1条答案
按热度按时间2ul0zpep1#
重写类
LoginView
上的方法get_context_data
。这假设
GET
参数将在参数next
中具有用户应该被重定向的下一个url。因此,请求的格式应为localhost.com/login?next=/accounts/