Django-allauth Sign Up, Login, and Social Connect

2019-04-11 12:30发布

问题:

How do you load both the Social Login, the Login form and Sign Up form to your Index page using django-allauth? Something similar like when you go to facebook.com.

accounts/url are already working and I've tried copying the

<form class="login" method="POST" action="{% url 'account_login' %}">
  {% csrf_token %}
  {{ form.as_p }}
  {% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
  {% endif %}
  <a class="button secondaryAction" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
  <button class="primaryAction" type="submit">{% trans "Sign In" %}</button>
</form>

to my index.html but it doesn't work. I'm new to Python Programming and Django development but i've done some excerise with tutorials in the Django Book.

回答1:

The view that handles your 'index' url and renders your index.html template has to have a login form, for that you have to make it a FormView descendant, and set the class attribute to LoginForm (allauth's login form). Otherwise, you can't render {{form.as_p}} to the template (because there is no form in your context).