S
S
sazhyk2016-08-03 08:37:58
Django
sazhyk, 2016-08-03 08:37:58

How to use allauth forms in your views?

I use allauth to register and authenticate users. I use django-bootstrap3 for styling. I want to use allauth forms in my views. Login form on the main page domain.com/. I do it like this.
views.py

from allauth.account.forms import LoginForm

def home(request):
    context = {
        'login_form': LoginForm
    }
    return render(request, 'home.html', context)

home.html
...
<form class="login" method="POST" action="{% url 'account_login' %}">
   {% csrf_token %}
   {% bootstrap_form login_form label='horizontal' %}
   {% if redirect_field_value %}
   <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
   {% endif %}
   <button type="submit" class="btn btn-primary">{% trans "Sign In" %}</button>
   <a class="button secondaryAction" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
</form>
...

All is well, the output is the allauth form in my home.html template. You can sign in. BUT! If you make a mistake in entering the login or password, then a redirect to the page occurs domain.com/accounts/login/. And I can't figure out where to override this redirect. Tell me please.
PS. I hope I formulated the question normally, if I said something wrong - write, I will supplement the question.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2016-08-03
@vintello

read here why it redirects to this page
, and in general you can specify the desired page in the LOGIN_REDIRECT_URL variable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question