【问题标题】:Django django.contrib.auth.views.password_reset_confirm error during template rendering模板渲染期间的 Django django.contrib.auth.views.password_reset_confirm 错误
【发布时间】:2016-10-06 19:07:29
【问题描述】:

我正在使用 django 视图实现用户密码重置,但 django.contrib.auth.views.password_reset_confirm 出现一些错误

重置密码的链接来自电子邮件:

MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Password reset on 127.0.0.1:8000
From: webmaster@localhost
To: progpyftk@yahoo.com
Date: Thu, 06 Oct 2016 19:01:30 -0000
Message-ID: <20161006190130.10100.76186@PEAMV57.exprogroup.local>


You're receiving this email because you requested a password reset for your user
 account at 127.0.0.1:8000.

Please go to the following page and choose a new password:

http://127.0.0.1:8000/account/password-reset/confirm/Mw/4fx-63795155cddbbad87a79
/

Your username, in case you've forgotten: Gileno

Thanks for using our site!

The 127.0.0.1:8000 team

当我点击链接时出现以下错误:

/account/password-reset/confirm/Mg/4fx-ee6f1fadc877a2279bdc/ 处的类型错误 字符串索引必须是整数

   return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
  File "C:\Python34\lib\site-packages\django\contrib\auth\password_validation.py
", line 29, in get_password_validators
    klass = import_string(validator['NAME'])
TypeError: string indices must be integers
[06/Oct/2016 16:02:59] "GET /account/password-reset/confirm/Mw/4fx-63795155cddbb
ad87a79/ HTTP/1.1" 500 201517

password_reset_confirm.html

{% extends "account/base.html" %}
{% block title %}Reset your password{% endblock %}
{% block content %}
    <h1>Reset your password</h1>
    <!-- We check if the provided link is valid. Django reset password view sets this variable
and puts it in the context of this template. If the link is valid, we display the user
password reset form. -->
    {% if validlink %}
        <p>Please enter your new password twice:</p>
        <form action="." method="post">
            {{ form.as_p }}
            {% csrf_token %}
            <p><input type="submit" value="Change my password"/></p>
        </form>
    {% else %}
            <p>The password reset link was invalid, possibly because it has already been used. Please request a new password reset.</p>
    {% endif %}
{% endblock %}

【问题讨论】:

    标签: django django-forms django-authentication


    【解决方案1】:

    您的AUTH_PASSWORD_VALIDATORS 设置似乎无效。它应该是一个字典列表。错误消息表明您有一个字符串列表。

    in the docs 给出的例子是:

    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
            'OPTIONS': {
                'min_length': 9,
            }
        },
        {
            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
    ]
    

    【讨论】:

    • 谢谢,在看到你的回答之前我就想通了,但你直截了当!
    猜你喜欢
    • 1970-01-01
    • 2017-07-03
    • 2020-11-18
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    • 2017-01-31
    • 2017-05-21
    相关资源
    最近更新 更多