Django内置了用于密码重置的身份验证视图-表单未显示

时间:2018-08-04 09:46:56

标签: python django passwords change-password

我正在尝试使用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')

1 个答案:

答案 0 :(得分:0)

您加载了脆皮标签吗?在您的{% load crispy_forms_tags %}

中加入reset_password.html
相关问题