“Django Passwort ändern” Code-Antworten

Djanog -Shell -Passwort ändern

from django.contrib.auth.models import User

usr = User.objects.get(username='your username')
usr.is_superuser=True
usr.is_staff=True
usr.set_password('raw password')
usr.save()
Clear Camel

Django -Passwort ändern Ansicht

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
    })
Sajib Hossain

Django ändern das Benutzerkennwort

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()
Clear Camel

Django Passwort ändern

python manage.py changepassword <user_name>
Obedient Osprey

Ändern Sie das Passwort django

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

Ähnliche Antworten wie “Django Passwort ändern”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen