1

所以我有用户(从 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'}),
)
4

2 回答 2

2

You have a wrong URL pattern defined: Django tries to find testdb.views.django.contrib.auth.views as you define the password_change view inside patterns('testdb.views',.

Add a second pattern:

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

That should resolve your issue.

于 2012-04-13T20:39:24.020 回答
0

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

于 2012-04-13T20:41:43.223 回答