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