我正在尝试使用django.contrib.auth视图来允许网站用户重置密码。但是,用户输入电子邮件地址以重置密码的电子邮件字段不会显示。表单标签显示为:
这就是它的样子屏幕截图
以下是我实现的内容,主要是对urls.py和模板所做的更改。如何解决此错误?非常感谢。
urls.py
from django.urls import path, include, re_path
from django.contrib.auth import views as authViews
urlpatterns = [
re_path(r'^account/password_reset/$', authViews.password_reset, {'template_name' : 'accounts/reset_password.html' }, name='password_reset'),
re_path(r'^account/password_reset/done/$', authViews.password_reset_done, {'template_name': 'accounts/reset_password_done.html'}, name='password_reset_done'),
re_path(r'^account/reset/(?P<uidb64>[0-9A-Za-z_-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', authViews.password_reset_confirm, {'template_name': 'accounts/reset_password_confirm.html'}, name='password_reset_confirm'),
re_path(r'^account/reset/done/$', authViews.password_reset_complete, {'template_name': 'accounts/reset_done.html'}, name='password_reset_complete'),
]
reset_password.html
<p class="text-center">If you have forgotten your password, please type your email address so we can send you a reset link.</p>
<form method="post">
{% csrf_token %}
<p> {{ form | crispy }} </p>
<button type="submit" class="btn btn-secondary mb-3 float-right">Reset Password</button>
</form>
forms.py文件在下面,尽管我认为它没有关联。附加信息,以防万一。
forms.py
from django import forms
from django.forms import ModelForm
from .models import Product, Category
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=100, required=True)
last_name = forms.CharField(max_length=100, required=True)
email = forms.EmailField(max_length=254, help_text='eg. youremail@anyemail.com')
class Meta:
model = User
fields = ('first_name','last_name','username','password1','password2')
class ProductForm(ModelForm):
class Meta:
model = Product
fields = ('name','slug','description','category','price','image','stock','available')
您加载了脆皮表单标签吗?在reset_password.html
中包含{% load crispy_forms_tags %}