对不起,我是个编程新手,所以很抱歉。 (从业余爱好开始,现在开始一个项目来代替与工作相关的任务,而不是使用excel)
尝试自定义用户模型并扩展django用户模型和身份验证形式,但不进行更新。
宁愿使用django编程来解决该问题,从而进一步了解django。 (不查看jQuery替代,不查看小部件柚木)
from django import forms
from django.contrib.auth.forms import AuthenticationForm
from .models import CustomUser
class CustomLoginForm(AuthenticationForm):
class Meta:
model: CustomUser
widgets = {
'username': forms.EmailInput(attrs={'class': 'form-control'}),
'password': forms.PasswordInput(attrs={'class': 'form-control'}),
}
from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
from users.forms import CustomLoginForm
from django.contrib.auth import views as auth_views
urlpatterns = [
path('admin/', admin.site.urls),
path('organisation/', include('organisation.urls')),
path('users/', include('django.contrib.auth.urls')),
path('users/login', auth_views.LoginView.as_view(template_name='registration/login.html',form_class='CustomLoginForm'), name ='login'),
<div class="card-body">
<form action="{% url 'login' %}" method="post">
{% csrf_token %}
<div class="form-group mb-3">
<label>{{ form.username.label_tag }}</label>
<div class="input-group">
{{ form.username }}
<span class="input-group-append">
<span class="input-group-text">
<i class="fas fa-user"></i>
</span>
</span>
</div>
</div>
<div class="form-group mb-3">
<div class="clearfix">
<label class="float-left">{{ form.password.label_tag }}</label>
<a href="pages-recover-password.html" class="float-right">Lost Password?</a>
</div>
<div class="input-group">
{{ form.password }}
<span class="input-group-append">
<span class="input-group-text">
<i class="fas fa-lock"></i>
</span>
</span>
</div>
</div>
<div class="row">
<div class="col-sm-8">
<div class="checkbox-custom checkbox-default">
<input id="RememberMe" name="rememberme" type="checkbox"/>
<label for="RememberMe">Remember Me</label>
</div>
</div>
<div class="col-sm-4 text-right">
<button type="submit" class="btn btn-primary mt-2">Sign In</button>
</div>
</div>