gpt4 book ai didi

django - allauth with crispyform : signup not working

转载 作者:行者123 更新时间:2023-12-05 07:39:52 24 4
gpt4 key购买 nike

我尝试使用 Crispy-form 增强我所有授权的注册表单,但它不起作用:)

我修改forms.py中的allauth表单,隐藏标签,添加按钮

我目前的问题是 forms.py 中的“self.helper.layout = Layout”使字段在模板中消失,但如果我评论 self.helper.layout = Layout,我没有一个按钮来验证我的表单 x(

我想要我的字段和我的表单的有效提交按钮,

感谢您的帮助!


详情如下


表单.py

from django import forms
from allauth.account.forms import SignupForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, ButtonHolder, Submit,Field
from crispy_forms.bootstrap import FormActions

class MySignupForm(SignupForm):
def __init__(self, *args, **kwargs):
super(MySignupForm, self).__init__(*args, **kwargs)

self.helper = FormHelper()
self.helper.form_show_labels = False
self.helper.layout = Layout(
FormActions(
Submit('submit', 'Sign-up', css_class = 'btn-primary')
),
)

我还在我的 settings.py 中定义我使用自定义表单作为注册

# CUSTOM : Allauth Setup part
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',

# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)

ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS = False
SOCIALACCOUNT_QUERY_EMAIL = ACCOUNT_EMAIL_REQUIRED
#Since users don't have account on the landing page, sign up redirect to thank you page
LOGIN_REDIRECT_URL = '/thank-you'
ACCOUNT_FORMS = {'signup': 'public.forms.MySignupForm'}

我用这个版本覆盖了 allauth 模板

{% extends "base.html" %}
{% load socialaccount %}
{% load crispy_forms_tags %}
{% load i18n %}

{% block head_title %}{% trans "Signup" %}{% endblock %}

{% block content %}
<section id="contact">
<div class="row">
<div class="container">
<div class="col-lg-12 text-center">
<h1 class="section-heading">{% trans "Sign Up" %}</h1>
</div>
<form class="signup" id="signup_form" method="post" action="{% url 'thankyou' %}">
{% crispy form %}
</form>

</div>
</div>
</section>
{% endblock %}

最佳答案

{% crispy form %}已经自己声明了<form></form> .我认为 <form> 的双重声明混淆浏览器。

替换:

    <form class="signup" id="signup_form" method="post" action="{% url 'thankyou' %}">
{% crispy form %}
</form>

通过:

{% crispy form %}

并插入forms.py:

class MySignUpForm(SignupForm):

def __init__(self, *args, **kwargs):
super(MySignUpForm, self).__init__(*args, **kwargs)

self.helper = FormHelper()
self.helper.form_id = 'signup_form'
self.helper.form_class = 'signup'
self.helper.form_method = 'post'
self.helper.form_action = reverse('thankyou')
# and then the rest as usual:
self.helper.form_show_labels = False
self.helper.add_input(Submit('signup', 'Sign Up'), css_class='btn btn-primary'))

关于django - allauth with crispyform : signup not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46790887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com