如何重置密码Django?

时间:2016-01-22 01:41:08

标签: python django

不知怎的,我几乎找不到任何关于此的信息。我找到了一个教程here,但它已经有4年了,似乎没什么帮助。我也经历了Django Documentation,但它没有给出很多示例代码。

我已设置urls.py

from django.conf.urls import url
from . import views
from django.contrib.auth import views as auth_views

urlpatterns = [
    url(r'^login/$', views.login_view, name='login'),
    url(r'^password_reset/$', auth_views.password_reset, {'post_reset_redirect' : '/accounts/password_reset_done/'}, name='password_reset'),
    url(r'^password_reset_done/$', auth_views.password_reset_done, name='password_reset_done'),
    url(r'^password_reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', auth_views.password_reset_confirm, {'post_reset_redirect' : '/accounts/password_done/'}, name='password_reset_confirm'),
    url(r'^password_done/$', auth_views.password_reset_complete, name='password_done'),
    url(r'^auth/$', views.login_auth, name='login_auth'),
    url(r'^register/$', views.register_user, name='register'),
    url(r'^logout/$', views.logout_user, name='logout'),
]

从我收集的内容来看,除非我使用自定义模板(我没有尝试过,因为我无法使用包含的Django版本),所以一切都在urls.py完成。

我可以让reset_password页面加载正常:

但是当我提交表单时,我收到以下错误:

我花了两个小时来修复这个完全相同的问题,以便加载reset_password页面,现在同样的问题正在发生,就在reset_password_confirm部分。我已经看了一堆解决这个确切错误的问题,但我不知道是什么导致了这个问题。处理urls.py中的几行似乎不应该这么难......

2 个答案:

答案 0 :(得分:2)

使用

更新您的urls.py.
public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    final double SHIRT_PRICE = 19.95;

    double shirt = SHIRT_PRICE;

    // Get number of shirts purchased.
    System.out.println("Enter the number of shirts "
            + "you have purchased to see your discount. ");

    int shirts = input.nextInt();

    double discount;
    switch (shirts) {

    case 1:
        discount = 0.0;
        break;
    case 2:
        discount = 0.0;
        break;
    case 3:
        discount = .10;
        break;
    case 4:
        discount = .10;
        break;
    case 5:
        discount = .20;
        break;
    case 6:
        discount = .20;
        break;
    case 7:
        discount = .20;
        break;
    case 8:
        discount = .30;
        break;
    case 9:
        discount = .30;
        break;
    case 10:
        discount = .30;
        break;
    case 11:
        discount = .30;
        break;
    case 12:
        discount = .40;
        break;
    default:
        discount = .40;
        break;

    }
    double finalDiscount = (shirt * shirts) * (1.0 - discount);

    System.out.println("Your discount is " + discount);
    System.out.println("Your total is " + finalDiscount);

    System.exit(1);

}

从日志中我可以看到它期待uidb64

答案 1 :(得分:0)

这正是我从文档中得到的,它完美无缺。

url(r'^admin/', include(admin.site.urls), name='admin'),  # admin interface
url(r'^login/', LoginView.as_view(), name='Login'),  # for user login
url(r'^logout/', LogoutView.as_view(), name='Logout'),  # logout
url(r'',include(admin.site.urls), name='admin'),  # logout
url(r'^admin/password_reset/$', auth_views.password_reset, name='admin_password_reset'),
url(r'^admin/password_reset/done/$', auth_views.password_reset_done, name='password_reset_done'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$', auth_views.password_reset_confirm, name='password_reset_confirm'),
url(r'^reset/done/$', auth_views.password_reset_complete, name='password_reset_complete'),

Here is the link to the docs, 希望它有所帮助。