use*_*275 8 django django-templates django-login
我想将用户名字段的标签更改为团队名称
注意:我正在使用内置的 LoginView
Luc*_*yne 16
根据文档 LoginView有一个名为authentication_form(通常只是一个表单类)的属性。默认为AuthenticationForm.
您可以创建一个继承自 的表单类AuthenticationForm,设置用户名字段的标签并将其分配给您的LoginViewoverauthentication_form属性。
表格.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})
)
Run Code Online (Sandbox Code Playgroud)
视图.py
from django.contrib.auth.views import LoginView
from .forms import CustomAuthenticationForm
class CustomLoginView(LoginView):
authentication_form = CustomAuthenticationForm
Run Code Online (Sandbox Code Playgroud)
网址.py
urlpatterns = [
path('login/', CustomLoginView.as_view(), name='login'),
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2585 次 |
| 最近记录: |