【问题标题】:link to django password reset not displaying链接到 django 密码重置不显示
【发布时间】:2020-10-06 16:36:45
【问题描述】:

密码重置链接未显示 密码重置的控制台输出 您好,有人要求重置电子邮件的密码 地址root@gmail.com,点击以下链接:http://127.0.0.1:8000{%url 'password_reset_confirm' uidb64=uid token=token %}

HTML 文件

password_reset.html

<form action="" method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="send password reset email" name="submit" />
</form>

password_reset_email.html

   Hi there, Someone asked for a password reset for the email
   address {{ email }}, Follow the link below: {{ protocol }}://
  {{ domain}} {% url'password_reset_confirm' uidb64=uid token=token %} 

password_reset_confirm.html

<div>
{% if validlink %}
<h2>change password for 0{{ form.user.username }}</h2>
 <form action="" method="POST" novalidate>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="changepassword" name="submit" />
</form>
{% else %}
<h3>Reset your password</h3>
<p>it looks like you clicked on an invalid passowrd reset link try again</p>
<a href="{% url 'password_reset' %}">Request</a>
{% endif %}
</div>

settings.py

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

acounts/urls.py

path("accounts/", include("django.contrib.auth.urls")),

【问题讨论】:

  • 您能否编辑您的问题以显示发送电子邮件的 Python 代码?

标签: django


【解决方案1】:

http://127.0.0.1:8000/accounts/password_reset/ 尝试这个 您只需添加链接到登录的 URL。

【讨论】:

【解决方案2】:

我遇到了同样的问题,我所要做的就是将代码放在同一行。

{{ protocol }}://{{ domain }}{% url "password_reset_confirm" uidb64=uid token=token %}
  1. 确保代码没有换行。

【讨论】:

    【解决方案3】:

    请检查以下事项。

    {{ protocol }}://{{ domain}} {% url'password_reset_confirm' uidb64=uid token=token %} 
    
    • 去掉{{ domain}} {% url''}之间的空格
    • 检查您的电子邮件模板是否对protocoldomain 有价值
    • 检查电子邮件并检查最终链接是什么。

    【讨论】:

    • 我检查了电子邮件中的链接。如何确保返回正确的domain?我的链接不是域之前的www,而是包含url5914。 @Ajay-saini
    猜你喜欢
    • 2019-04-30
    • 1970-01-01
    • 2012-02-10
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 2020-08-16
    • 1970-01-01
    相关资源
    最近更新 更多