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.
DjangoBlog/accounts/forms.py

19 lines
948 B

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 import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser
# HJJ: 自定义用户创建表单继承Django内置的UserCreationForm
class CustomUserCreationForm(UserCreationForm):
class Meta:
# HJJ: 指定表单对应的模型为CustomUser
model = CustomUser
# HJJ: 定义表单中包含的字段:用户名、邮箱、个人简介、头像、位置、网站
fields = ('username', 'email', 'bio', 'avatar', 'location', 'website')
# HJJ: 自定义用户信息修改表单继承Django内置的UserChangeForm
class CustomUserChangeForm(UserChangeForm):
class Meta:
# HJJ: 指定表单对应的模型为CustomUser
model = CustomUser
# HJJ: 定义表单中包含的字段:用户名、邮箱、个人简介、头像、位置、网站
fields = ('username', 'email', 'bio', 'avatar', 'location', 'website')