Django 显示的RadioSelect字段不正确
我将RadioSelect字段放在表单中,在Chromium中,我的选择位于表单的左侧,不像标签和其他位于中心的字段,如何修复它?请给我一些建议。在FF中,它的外观也不同,它位于左侧 模板Django 显示的RadioSelect字段不正确,django,django-forms,django-templates,Django,Django Forms,Django Templates,我将RadioSelect字段放在表单中,在Chromium中,我的选择位于表单的左侧,不像标签和其他位于中心的字段,如何修复它?请给我一些建议。在FF中,它的外观也不同,它位于左侧 模板 {% extends 'school/index.html' %} {% load crispy_forms_tags %} {% load crispy_forms_field %} {% block content %} <form method="post" align='
{% extends 'school/index.html' %}
{% load crispy_forms_tags %}
{% load crispy_forms_field %}
{% block content %}
<form method="post" align='center' autocomplete="off" novalidate>
{% csrf_token %}
{{ form|crispy }}
<button type="submit" class="btnSubmit">submit</button>
</form>
{% endblock %}
您能同时添加CSS代码吗?在模板中,我更改了新版本。在较旧的4.3.1上启动并修复它。
from django import forms
from django.contrib.auth.models import User
from django.core.validators import MinLengthValidator
from django.utils.translation import gettext_lazy as _
class UserSignUpForm(forms.ModelForm):
who = forms.ChoiceField(
choices=[('student', 'Student'), ('teacher', 'Teacher')],
required=True,
widget=forms.RadioSelect(attrs={'style':'max-width: 20em; margin:auto; padding:300;',
'autocomplete':'off'})
)
password = forms.CharField(
label="Password",
validators=[MinLengthValidator(8, message="Minimum 8 characters")],
widget=forms.PasswordInput(attrs={'style':'max-width: 20em; margin:auto',
'autocomplete':'off'}))
confirm_password = forms.CharField(
label="Confirm password",
validators=[MinLengthValidator(8, message="Minimum 8 characters"), ],
widget=forms.PasswordInput(attrs={'style':'max-width: 20em; margin:auto',
'autocomplete':'off'}))
class Meta:
model = User
fields = ('who', "username", 'first_name', 'last_name', "password", )
help_texts = {"username": None}
widgets = {
'username': forms.TextInput(attrs={'style':'max-width: 20em; margin:auto'}),
'first_name': forms.TextInput(attrs={'style':'max-width: 20em; margin:auto'}),
'last_name': forms.TextInput(attrs={'style':'max-width: 20em; margin:auto'}),
}
def clean(self):
cleaned_data = super(UserSignUpForm, self).clean()
password = cleaned_data.get("password")
confirm_password = cleaned_data.get("confirm_password")
if password != confirm_password:
msg = _(f'Password and confirm password does not match')
self.add_error('password', msg)
self.add_error('confirm_password', msg)