How to use a signup form outside of the /accounts/ url pattern with Django-AllAuth?

醉酒当歌 提交于 2019-12-11 03:19:43

问题


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?


回答1:


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 %}


来源:https://stackoverflow.com/questions/27901991/how-to-use-a-signup-form-outside-of-the-accounts-url-pattern-with-django-allau

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!