Reputation: 4669
I'm currently using django-allauth to manage my registrations and logins.
Until now, all of my logins and signups have worked by having the django-allauth pages at the /accounts/
prefix for url patterns, so to register a new account you would navigate to /accounts/signup/
. I want to keep this functionality, but also want to introduce a signup form onto my landing page (at my base url), and I want to have a quick login form in my top banner from anywhere in my website (not /accounts/
).
My question is simple, how can we create login and signup forms anywhere throughout the site, without restricting it to a specific prefix of my urls?
Upvotes: 2
Views: 937
Reputation: 2052
If you want to create a signup/login form in your landing page or somewhere else, you can take a look at this question: https://stackoverflow.com/a/24179796/2230003
Basically, for a login/logout form using e-mail only and not username to login, the code in your template would be:
{% load account %}
<h1>Login / Logout</h1>
{% if user.is_authenticated %}
<p>Loged in with e-mail: {{ request.user.email }}</p>
<a href="{% url "account_logout" %}">Logout</a>
{% else %}
<form action="{% url "account_login" %}" method="post">
{% csrf_token %}
<input type="email" placeholder="E-mail" name="login">
<input type="password" placeholder="Password" name="password">
<label for="id_remember_menu" class="text-primary">Remember Me:</label>
<input id="id_remember_menu" name="remember" type="checkbox">
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button type="submit">Login</button>
<a href="{% url 'account_reset_password' %}">Forgot Password?</a>
</form>
{% endif %}
Upvotes: 1