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.
from django . contrib . auth . forms import forms
from django . forms import widgets
# 定义一个表单类,用于在 OAuth 登录时补充或验证邮箱信息
class RequireEmailForm ( forms . Form ) :
# 邮箱字段,必填
email = forms . EmailField ( label = ' 电子邮箱 ' , required = True )
# OAuth 用户 ID( 隐藏字段, 用于在后台提交时识别用户)
oauthid = forms . IntegerField ( widget = forms . HiddenInput , required = False )
# 构造函数,用来自定义表单字段的显示样式
def __init__ ( self , * args , * * kwargs ) :
# 调用父类初始化方法
super ( RequireEmailForm , self ) . __init__ ( * args , * * kwargs )
# 自定义 email 输入框的 HTML 样式与属性
self . fields [ ' email ' ] . widget = widgets . EmailInput (
attrs = {
' placeholder ' : " email " , # 输入框占位提示文字
" class " : " form-control " # Bootstrap 样式类,统一表单外观
}
)