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

标签 python django passwords django-templates authentication

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

"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'}),
)

最佳答案

您定义了错误的 URL 模式:当您在 patterns('testdb.views' ) 中定义 password_change View 时,Django 会尝试查找 testdb.views.django.contrib.auth.views

添加第二个模式:

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

这应该可以解决您的问题。

关于python - DJANGO:如何允许用户更改密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10147749/

相关文章:

python - sqlalchemy 嵌套继承/多态关系

python - Bigquery(和 pandas)- 确保数据插入一致性

python - 从网页上传图像

python - 使用 pip 从 Web 项目的 requirements.txt 安装时出错

ssl - 通过 websocket 登录 - 这安全吗?

c - 在 C 中输入密码

python - 在 python 3 中“尝试” 'duration'

python - 在 Django 中收集来自第三方应用程序的消息

node.js - 在 Node.js 中生成和验证密码哈希值与 Python 的 werkzeug 相同

python - Django:想要将一个空字段显示为空白而不是显示无