Django 内置用于密码重置的身份验证视图 - 表单未显示
Django built in auth views for password reset - Form not showing
我正在尝试使用 django.contrib.auth 视图来允许网站用户重设密码。但是,没有显示供用户输入电子邮件地址以重置密码的电子邮件字段。显示的是表单标签:
这是它的样子
screenshot
以下是我实现的,主要是在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 %}
我正在尝试使用 django.contrib.auth 视图来允许网站用户重设密码。但是,没有显示供用户输入电子邮件地址以重置密码的电子邮件字段。显示的是表单标签:
这是它的样子 screenshot
以下是我实现的,主要是在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 %}