gpt4 book ai didi

python - 如何更改默认 Django 重置密码电子邮件模板引用的 View 名称?

转载 作者:太空宇宙 更新时间:2023-11-03 17:55:12 26 4
gpt4 key购买 nike

这是 Django 1.7 中默认的重置密码电子邮件模板:

{% load i18n %}{% autoescape off %}
{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %}

{% trans "Please go to the following page and choose a new password:" %}
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
{% endblock %}
{% trans "Your username, in case you've forgotten:" %} {{ user.get_username }}

{% trans "Thanks for using our site!" %}

{% blocktrans %}The {{ site_name }} team{% endblocktrans %}

{% endautoescape %}

在我的 urls.py 中,password_reset_confirm View 使用此备用名称:password_reset_3of4_new_password_form

from django.conf.urls import patterns, url
#Passing keyword arguments through url entries:
# - https://docs.djangoproject.com/en/1.7/topics/http/urls/#passing-extra-options-to-view-functions
urlpatterns = patterns('',
url(r"^login/$", "auth_lifecycle.registration.views.login_maybe_remember",
name="login"),
url(r"^logout_then_login/$", "django.contrib.auth.views.logout_then_login",
{"login_url": "login"}, name="logout_then_login"),
url(r"^password_reset_1of4_email_request/$",
"django.contrib.auth.views.password_reset",
{ "template_name": "registration/password_reset_1of4_email_request.html",
"post_reset_redirect": "password_reset_2of4_email_sent" },
name="password_reset_1of4_email_request"),
url(r"^password_reset_2of4_email_sent/$",
"django.contrib.auth.views.password_reset_done",
{ "template_name": "registration/password_reset_2of4_email_sent.html" },
name="password_reset_2of4_email_sent"),
url(r"^pwd_reset_3of4_new_pwd_form/(?P<uidb64>\w+)/(?P<token>[\w-]+)/$",
"django.contrib.auth.views.password_reset_confirm",
name="password_reset_3of4_new_password_form"), #<--HERE
url(r"^password_reset_4of4_finished/$",
"django.contrib.auth.views.password_reset_complete",
name="password_reset_4of4_finished"),
)

有什么方法可以更改默认电子邮件模板使用的 View 名称吗?我在 password_reset 中没有看到任何相关参数看法。我希望避免手动复制然后编辑此模板(然后由 email_template_name 参数引用)。

最佳答案

模板中的 View 名称是字符串文字,而不是变量,因此您无法在不更改模板的情况下覆盖它。

如果您使用 email_template_name 参数指定不同的模板,则可以扩展原始模板,并覆盖您要更改的特定 block 。

{% extends "registration/password_reset_email.html" %}
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url 'password_reset_3of4_new_password_form' uidb64=uid token=token %}
{% endblock %}

就我个人而言,我认为以这种方式更改 View 名称会让任何其他习惯了原始名称的 Django 开发人员感到困惑。

关于python - 如何更改默认 Django 重置密码电子邮件模板引用的 View 名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28569130/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com