如何使用Django-AllAuth在/accounts/网址格式之外使用注册表单? [英] How to use a signup form outside of the /accounts/ url pattern with Django-AllAuth?

查看:182
本文介绍了如何使用Django-AllAuth在/accounts/网址格式之外使用注册表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用django-allauth来管理我的注册和登录.

I'm currently using django-allauth to manage my registrations and logins.

到目前为止,我的所有登录和注册都通过在URL模式的/accounts/前缀处具有django-allauth页面进行,因此,要注册一个新帐户,您可以导航至/accounts/signup/.我想保留此功能,但也想在我的目标网页上(在我的基本URL上)引入一个注册表单,并且希望在我网站的任何位置(而不是/accounts/)的顶部横幅中都有一个快速登录表单.

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/).

我的问题很简单,我们如何在整个站点的任何地方创建登录和注册表单,而又不将其限制为我的URL的特定前缀?

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?

推荐答案

如果要在登录页面或其他地方创建注册/登录表单,可以查看以下问题:

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

这篇关于如何使用Django-AllAuth在/accounts/网址格式之外使用注册表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆