thedeepfield
thedeepfield

Reputation: 6196

DJANGO: How to allow Users to change password?

So I have Users (from django.contrib.auth.models import User) and UserProfiles. in my UserProfile view there is an edit link. This edit link allows a User to change their User settings. In the password section of the form I see help text that says:

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

The "change password form" is actually a link to http://127.0.0.1:8000/user/1/user_edit/password/, when I click the link I get an error message saying:

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

I've been following the documentation: https://docs.djangoproject.com/en/dev/topics/auth/

What am I doing wrong? I hear that this should use djangos templates, do I need to copy those over to my apps template folder? if so, where are they?

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

Upvotes: 1

Views: 5769

Answers (2)

cfedermann
cfedermann

Reputation: 3284

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.

Upvotes: 2

Daniel Roseman
Daniel Roseman

Reputation: 599926

cfedermann has a solution to your issue, but I'm confused as to why you've defined the password_change URL in the first place. This functionality is built-in to the admin, and - like all the other admin pages - the URL is defined already by the admin code itself.

Upvotes: 0

Related Questions