Created
August 4, 2016 09:08
-
-
Save vitorfs/1d538f6b27891055de2ca25a05e04bb1 to your computer and use it in GitHub Desktop.
Django Change Password View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post"> | |
{% csrf_token %} | |
{{ form }} | |
<button type="submit">Save changes</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import url | |
from myproject.accounts import views | |
urlpatterns = [ | |
url(r'^password/$', views.change_password, name='change_password'), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import messages | |
from django.contrib.auth import update_session_auth_hash | |
from django.contrib.auth.forms import PasswordChangeForm | |
from django.shortcuts import render, redirect | |
from django.utils.translation import ugettext as _ | |
def change_password(request): | |
if request.method == 'POST': | |
form = PasswordChangeForm(request.user, request.POST) | |
if form.is_valid(): | |
user = form.save() | |
update_session_auth_hash(request, user) | |
messages.success(request, _('Your password was successfully updated!')) | |
return redirect('accounts:change_password') | |
else: | |
messages.error(request, _('Please correct the error below.')) | |
else: | |
form = PasswordChangeForm(request.user) | |
return render(request, 'accounts/change_password.html', { | |
'form': form | |
}) |
Sorry for disturb you. Please could you guide me to create custom userpassword change form in django
You only set id for customizing form and the id set for the same Django inbuilt form ( https://i.imgur.com/rWQIYlS.png )
can you sent form pls!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
He has a post about this on his website: https://simpleisbetterthancomplex.com/tips/2016/08/04/django-tip-9-password-change-form.html