DJANGO:如何允许用户更改密码?

时间:2012-04-13 20:17:01

标签: python django passwords django-templates authentication

所以我有用户(来自django.contrib.auth.models导入用户)和UserProfiles。在我的UserProfile视图中有一个编辑链接。此编辑链接允许用户更改其用户设置。在表单的密码部分,我看到帮助文本说:

"Use '[algo]$[salt]$[hexdigest]' or use the change password form." 

“更改密码表单”实际上是http://127.0.0.1:8000/user/1/user_edit/password/的链接,当我点击链接时收到错误消息:

ViewDoesNotExist at /user/1/user_edit/password/

Could not import testdb.views.django.contrib.auth.views. Error was: No module named django.contrib.auth.views

我一直在关注文档:https://docs.djangoproject.com/en/dev/topics/auth/

我做错了什么?我听说这应该使用djangos模板,我需要将它们复制到我的应用模板文件夹吗?如果是的话,他们在哪里?

URLS.PY

from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('testdb.views',
url(r'^$', 'index'),
url(r'^^user/(?P<user_id>\d+)/$', 'user_detail'),
url(r'^user/(?P<user_id>\d+)/user_edit/$', 'user_edit'),
url(r'^user/(?P<user_id>\d+)/user_edit/password/$', 'django.contrib.auth.views.password_change', {'template_name': 'password_change_form'}),
)

2 个答案:

答案 0 :(得分:2)

您定义了错误的网址格式:当您在testdb.views.django.contrib.auth.views中定义password_change视图时,Django会尝试查找patterns('testdb.views',

添加第二种模式:

urlpatterns += patterns('django.contrib.auth.views',
  url(r'^user/(?P<user_id>\d+)/user_edit/password/$', 'password_change')
)

这应解决您的问题。

答案 1 :(得分:0)

cfedermann解决了您的问题,但我很困惑为什么您首先定义了password_change网址。此功能内置于管理员,并且 - 与所有其他管理页面一样 - URL已由管理代码本身定义。