How can I get the django allauth signup page to show up without being at the /accounts/login url?

大憨熊 提交于 2019-12-24 00:28:33

问题


A lot of websites such as pinterest, facebook, and tumblr have their signup page at their home page. Is it possible to get the allauth login page to show on the home page rather than the /accounts/login page?


回答1:


Sure can! Just route whichever url you want to go to the allauth login view

from django.conf.urls import patterns, include, url
from main import views
from allauth.account import views as allauthviews

urlpatterns = patterns('',
    url(r'^$', allauthviews.login),
    url(r'^someurl/$', views.home)
)



回答2:


If you want to use your own home page and only add the signup/login forms there, you can also take a look at this question: Log in / Sign up directly on home page

Basically, for a login/logout form using e-mail only and not username to login, the code 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/25777241/how-can-i-get-the-django-allauth-signup-page-to-show-up-without-being-at-the-ac

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