【问题标题】:Forgot Password function, django忘记密码功能,django
【发布时间】:2011-10-19 04:14:27
【问题描述】:

我按照这里的代码: http://drumcoder.co.uk/blog/2010/apr/09/django-reset-password/ 以及这里: http://shrenikp.webs.com/apps/blog/entries/show/7133721-implement-forgot-password-on-customer-ui- 和这里: http://blog.montylounge.com/2009/07/12/django-forgot-password/

这是我目前希望使用的代码以及我目前拥有的代码

[base.html]

            <form name="login_form" action="/login/" method="post" accept-charset="utf-8" style="display: inline">
                {% csrf_token %}
                Username: <input type="text" name="username" value="" /><br />
                Password: <input type="password" name="password" value="" /><br />
                <input type="submit" value="submit" value = "" id ="submit" />
                <p><a href="{% url password_reset %}">Forgot password?</a></p>
            </form>

[url.py]

urlpatterns = patterns('',
    url(r'^password_reset/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
    (r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
    (r'^reset/(?P[0-9A-Za-z]+)-(?P.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
    (r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
)

我收到类似这样的错误:

unknown specifier: ?P[

由于某种原因出现此行错误... (r'^reset/(?P[0-9A-Za-z]+)-(?P.+)/$' 有什么帮助吗?

【问题讨论】:

    标签: django passwords reset


    【解决方案1】:

    你需要把它改成这样:

    (r'^reset/(?P<uidb36>[-\w]+)/(?P<token>[-\w]+)/$', 'django.contrib.auth.views.password_reset_confirm')
    

    您需要在模板中的&lt;form&gt; 标记之后添加标签{% csrf_token %}。试试看。

    【讨论】:

    • 好的,谢谢!那成功了。但是现在我有这个错误 Forbidden (403) CSRF 验证失败。请求中止。你能帮我吗?
    • 奇怪,我查看了 django lib 使用的 url 规则及其:(r'^account/reset/(?P&lt;uidb36&gt;[0-9A-Za-z]{1,13})-(?P&lt;token&gt;[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$'
    猜你喜欢
    • 2013-12-09
    • 2011-09-28
    • 1970-01-01
    • 2017-07-06
    • 2012-02-22
    • 2013-10-12
    • 2013-05-17
    • 2011-01-17
    • 2013-12-01
    相关资源
    最近更新 更多