【发布时间】:2018-08-04 09:46:56
【问题描述】:
我正在尝试使用 django.contrib.auth 视图来允许网站用户重置他们的密码。但是,用户输入电子邮件地址以重置密码的电子邮件字段未显示。而是显示表单标签:
这就是它的样子 screenshot
以下是我自己实现的,主要只是对urls.py和templates做了一些改动。我该如何解决这个错误?谢谢。
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')
【问题讨论】:
标签: python django passwords change-password