Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django password change view

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

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)  # Important!
            messages.success(request, 'Your password was successfully updated!')
            return redirect('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
    })
Comment

change password django

>>> from django.contrib.auth.models import User
>>> u = User.objects.get(username='john')
>>> u.set_password('new password')
>>> u.save()
Comment

PREVIOUS NEXT
Code Example
Python :: Static Assets in Django 
Python :: seconds add zero python 
Python :: SafeERC20: low-level call failed 
Python :: python datetime subtract seconds 
Python :: boto3 with aws profile 
Python :: unpack tuple python 
Python :: chi square test in python 
Python :: python temporaty files 
Python :: python last element of list 
Python :: skip rows in pandas read excel 
Python :: python if not path exist make path 
Python :: how to insert a variable into a string without breaking up the string in python 
Python :: tkinter remove frame 
Python :: how to make a complex calculator in python 
Python :: opencv set window size 
Python :: Set column as index with pandas 
Python :: spacy remove stop words 
Python :: Pyo example 
Python :: python check version 
Python :: recursive python program to print numbers from n to 1 
Python :: Python find inverse of matrix 
Python :: roll longitude about zero 
Python :: python emoji 
Python :: how to install python 3.6 ubuntu 
Python :: pygame mute import message 
Python :: how to remove duplicate files from folder with python 
Python :: list of strings to numbers python 
Python :: check numpy arrays equal 
Python :: print hello world python 
Python :: How to set up flash message in html template in flask app 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =