2👍
I don’t understand. your condition is on POST mode
if request.method == “POST”
And you try redirect with an GET argument…
You need to pass ‘next’ value in your form, and get it with POST[‘next’]
Example :
if 'next' in request.POST:
return HttpResponseRedirect(request.POST['next'])
else:
return HttpResponseRedirect('/home/')
0👍
Resolved by adding hidden field for next
param.login.html is
form class="form-signin" method="post" action="{% url 'login' %}">{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}" />
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="text" id="inputEmail" class="form-control" placeholder="Username" required="" autofocus="" name="username">
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required="" name="password">
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
And my login view is,
def login(request):
if request.method == 'GET':
template='login.html'
context = {}
next = request.GET.get('next',None)
if next:
context['next'] = next
return render(request,template,context)
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login_user(request, user)
template='home.html'
return HttpResponseRedirect(request.POST['next'])
else:
raise Http404("User is not active")
Problem solved by a hidden field. but to me it was not clear with the doc
- [Answered ]-Skip celery warnings
- [Answered ]-Django MEDIA_ROOT, MEDIA_URL etc
- [Answered ]-Django: Update or Change previous saved model data
- [Answered ]-How can I get rid of legacy tasks still in the Celery / RabbitMQ queue?
- [Answered ]-How to temporarily disable foreign key constraint in django
Source:stackexchange.com