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.
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.
# 导入Django的表单基类和 widgets( 表单控件)
from django . contrib . auth . forms import forms
from django . forms import widgets
# 定义一个要求用户输入邮箱的表单类, 继承自基础表单类forms.Form
class RequireEmailForm ( forms . Form ) :
# 定义邮箱字段:标签为“电子邮箱”,且为必填项
email = forms . EmailField ( label = ' 电子邮箱 ' , required = True )
# 定义oauthid字段: 使用隐藏输入控件( 不在页面显式展示) , 非必填
oauthid = forms . IntegerField ( widget = forms . HiddenInput , required = False )
# 重写初始化方法,用于自定义表单字段的控件属性
def __init__ ( self , * args , * * kwargs ) :
# 调用父类的初始化方法,确保基础功能正常
super ( RequireEmailForm , self ) . __init__ ( * args , * * kwargs )
# 为email字段设置自定义控件:
# 使用EmailInput控件, 添加placeholder提示文本和CSS类
self . fields [ ' email ' ] . widget = widgets . EmailInput (
attrs = { ' placeholder ' : " email " , " class " : " form-control " } )