我有这个课我需要继承。
class AuthenticationForm(forms.Form):
username = forms.CharField(label=_("Username"), max_length=30)
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
def __init__(self, request=None, *args, **kwargs):
super(AuthenticationForm, self).__init__(*args, **kwargs)
你能告诉我如何继承这个并从超类中删除username
变量吗?
class LoginForm(AuthenticationForm):
email = forms.EmailField(
required=True, label=_("Email")
)
def __init__(self, request, *args, **kwargs):
#del super(LoginForm, self).username
super(LoginForm, self).__init__(
request, *args, **kwargs
)
由于
答案 0 :(得分:3)
由于这是Django,你可以从fields
dict中删除它:
class LoginForm(…):
def __init__(…):
super(LoginForm, self).__init__(…)
self.fields.pop('username')