Однако, как только я перешел от Django 5.0 до 5.1, я увидел измененное поведение с моей страницей «Создать новый пользователь», на которой используется форма подписи , которая позволяет пустые пароли. Если пароль не поставляется, сгенерирован случайный. Оба явно установленные по мере необходимости = false .
Я видел, что были изменены пользовательские изменения django 5.1.0 и 5.1.1. Я попытался использовать AdminuserCreationForm и установить поле usable_password на None , но оно все еще не допускает пустых паролей, как раньше.
Есть идеи?
среда < /strong>
python 3.12.8
django 5.1.5
Crispy Forms 2.3
упрощенный код
Код: Выделить всё
from django.contrib.auth.forms import AdminUserCreationForm
from crispy_forms.helper import FormHelper
class SignupForm(AdminUserCreationForm): # previously using UserCreationForm
usable_password = None # Newly added
# Form fields
sharedaccountflag = forms.ChoiceField(
label = 'Cuenta compartida',
required = True,
choices = BOOLEAN_CHOICES
)
# Constructor
def __init__(self, *args, **kwargs):
# Call base class constructor
super(SignupForm, self).__init__(*args, **kwargs)
# Set password fields as optional
self.fields['password1'].required = False
self.fields['password2'].required = False
# Set form helper properties
self.helper = FormHelper()
self.helper.form_tag = False
# Specify model and which fields to include in form
class Meta:
model = get_user_model()
fields = ('password1', 'password2', 'sharedaccountflag')

Подробнее здесь: https://stackoverflow.com/questions/793 ... -passwords
Мобильная версия