You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
text/user/form.py

21 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from django.contrib.auth.forms import UserCreationForm
from .models import MyUser
from django import forms
# 定义MyUser的数据表单用于用户注册
class MyUserCreationForm(UserCreationForm):
# 重写初始化函数设置自定义字段password1和password2的样式和属性
def __init__(self, *args, **kwargs):
super(MyUserCreationForm, self).__init__(*args, **kwargs)
self.fields['password1'].widget = forms.PasswordInput(attrs={'class': 'txt tabInput', 'placeholder':'密码,4-16位数字/字母/特殊符号(空格除外)'})
self.fields['password2'].widget = forms.PasswordInput(attrs={'class': 'txt tabInput', 'placeholder':'重复密码'})
class Meta(UserCreationForm.Meta):
model = MyUser
# 在注册界面添加模型字段:手机号码和密码
fields = UserCreationForm.Meta.fields +('mobile',)
# 设置模型字段的样式和属性
widgets = {
'mobile': forms.widgets.TextInput(attrs={'class': 'txt tabInput', 'placeholder':'手机号'}),
'username': forms.widgets.TextInput(attrs={'class': 'txt tabInput', 'placeholder':'用户名'}),
}