我想使用原始的django注册号做一个自定义密码重设表单,该表单中包含recaptcha。这是相关代码:
forms.py
from django.contrib.auth.forms import PasswordResetForm
from snowpenguin.django.recaptcha2.fields import ReCaptchaField
from snowpenguin.django.recaptcha2.widgets import ReCaptchaWidget
class CaptchaPasswodResetForm(PasswordResetForm):
captcha = ReCaptchaField(widget=ReCaptchaWidget())
urls.py
from django.conf.urls import url
from landingpage.forms import CaptchaPasswodResetForm
from django.contrib.auth import views as auth_views
urlpatterns = [
url(r'^password-reset/$', auth_views.password_reset, {'password_reset_form': CaptchaPasswodResetForm}, name='new_password_reset'),
url(r'^password-reset-done/$', auth_views.password_reset_done, name='password_reset_done'),
]
password_reset_form.html
{% extends "base.html" %}
{% load i18n %}
{% load recaptcha2 %}
{% block head %}
{% recaptcha_init %}
{% endblock %}
{% block content %}
<form method="post" action=".">
{% csrf_token %}
{{ password_reset_form.as_p}}
<input type="submit" value="{% trans 'Submit' %}" />
</form>
{% endblock %}
应该发生的是,由于我添加了url标签,因此表单的字段显示在模板中。但是,当我将标签放入模板时,模板基本上只会忽略它。当我使用“表单”时,它使用默认的密码重置表单。有什么我想念或做错的事吗?