Reputation: 1395
I have an input field <input type="hidden" name="next" value="{{ next }}" />
, but it wont replace {{ next }}
with the value of the GET parameter. I can't find how to replace the value.
My view
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
Upvotes: 0
Views: 1633
Reputation: 15221
Override method get_context_data
on class LoginView
.
def get_context_data(self, **kwargs):
context = super(LoginView, self).get_context_data(**kwargs)
context['next'] = self.request.REQUEST.get('next')
return context
This assumes that the GET
parameter will have the next url where user should be redirected in param next
. So, request should be of form localhost.com/login?next=/accounts/
Upvotes: 1