答案 0 :(得分:2)
根据documentation LoginView
具有一个称为authentication_form
的属性(通常只是一个表单类)。默认为AuthenticationForm
。
您可以创建一个继承自AuthenticationForm
的表单类,设置用户名字段的标签,并将其分配给LoginView
属性上的authentication_form
。
forms.py
from django import forms
from django.contrib.auth.forms import AuthenticationForm, UsernameField
class CustomAuthenticationForm(AuthenticationForm):
username = UsernameField(
label='Team Name',
widget=forms.TextInput(attrs={'autofocus': True})
)
views.py
from django.contrib.auth.views import LoginView
from .forms import CustomAuthenticationForm
class CustomLoginView(LoginView):
authentication_form = CustomAuthenticationForm
答案 1 :(得分:0)
只需更改用户名字段的标签文本,如下所示:
class LoginForm(ModelForm):
class Meta:
model = YourModel
fields = ['username','password']
def __init__(self, *args, **kwargs):
super(LoginForm, self).__init__(*args, **kwargs)
for fieldname in ['username']:
self.fields[fieldname].label = 'Email'