Django将占位符添加到内置登录表单的django中

Django将占位符添加到内置登录表单的django中,第1张

Django将占位符添加到内置登录表单的django中

将此内容保存在

forms.py

from django import formsfrom django.contrib.auth.forms import AuthenticationFormfrom django.forms.widgets import PasswordInput, TextInputclass CustomAuthForm(AuthenticationForm):    username = forms.CharField(widget=TextInput(attrs={'class':'validate','placeholder': 'Email'}))    password = forms.CharField(widget=PasswordInput(attrs={'placeholder':'Password'}))

在您的主目录

urls.py
(您的登录视图称为)中

from django.contrib.auth import views as auth_viewsfrom app.forms import CustomAuthFormurlpatterns = [url(r'^login/$', auth_views.login, name='login', kwargs={"authentication_form":CustomAuthForm}),]

我们在这里做的额外的事情是增加了kwargs

kwargs={"authentication_form":CustomAuthForm}

请使用它作为将来的参考
django.contrib.auth.views.LoginView和django.contrib.auth.forms.AuthenticationForm



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5664100.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存