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

django change user password

python manage.py shell

from django.contrib.auth.models import User

usr = User.objects.get(username='your username')
usr.set_password('raw password')
usr.save()
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

set password django

myuser.groups.set([group_list])
myuser.groups.add(group, group, ...)
myuser.groups.remove(group, group, ...)
myuser.groups.clear()
myuser.user_permissions.set([permission_list])
myuser.user_permissions.add(permission, permission, ...)
myuser.user_permissions.remove(permission, permission, ...)
myuser.user_permissions.clear()
Comment

PREVIOUS NEXT
Code Example
Python :: How to get the date from week number in Python? 
Python :: python lists 
Python :: append a list to a list python 
Python :: windows how to store filepath as variabley python 
Python :: how to access the last element of a list in python 
Python :: python format strings 
Python :: how to change the disabled color in tkinter 
Python :: convert string to float python 
Python :: what is kernel_initializer 
Python :: display multiple dataframe as table jupyter notebook 
Python :: discord.py send message to user id 
Python :: how to add array in python 
Python :: how to hide ticks marks in plot 
Python :: remove  python 
Python :: pandas read csv without scientific notation 
Python :: decode utf8 whit python 
Python :: f-string print 
Python :: url_for 
Python :: rename column by indexing 
Python :: python count 
Python :: def factorial python 
Python :: make a post request in python 
Python :: python recursion factorial 
Python :: raw input example python 
Python :: Add PostgreSQL Settings in Django 
Python :: Jinja for items in list 
Python :: python code to demonstrate inheritance 
Python :: name, *line = input().split() 
Python :: Reason: Worker failed to boot 
Python :: string upper lower count python 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =