Allauth Login On Homepage Not Working
To allow Django's allauth to work on my homepage, I copied the allauth HTML for the login and signup forms to my own base.html (The login form can be seen here). So this successful
Solution 1:
Managed to fix it by passing in the forms as context in my view:
from allauth.account.forms import LoginForm, SignupForm
allauth_login = LoginForm(request.POST orNone)
allauth_signup = SignupForm(request.POST orNone)
context = {
'posts': posts,
'allauth_login': allauth_login,
'allauth_signup': allauth_signup
}
Then replacing {{ form.as_p }}
for {{ allauth_login }}
in my template:
<formclass="login"method="POST"action="{% url 'account_login' %}"><divclass="loginWrapper"><divclass="loginNested"><divclass="loginBox">
{% csrf_token %}
{{ allauth_login }}
{% if redirect_field_value %}
<inputtype="hidden"name="{{ redirect_field_name }}"value="{{ redirect_field_value }}" />
{% endif %}
<aclass="button secondaryAction"href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a><buttonclass="primaryAction"type="submit">{% trans "Sign In" %}</button></div></div></div></form>
This method only works when the credentials are entered correctly. So when entered correctly the form successfully submits and logs in/signs up. However when credentials are entered incorrectly for login, or when a username is already taken for signup etc, it will submit the form anyway and redirect me to /accounts/login or /accounts/signup. This is different to the normal allauth which shows errors without submitting the form. If anyone could tell me how to show errors that would be great, otherwise I will post a seperate question.
Post a Comment for "Allauth Login On Homepage Not Working"