“Ubah Kata Sandi Django” Kode Jawaban

Django Kata Sandi Perubahan Tampilan

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 Ubah Kata Sandi Pengguna

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 mengubah baris perintah kata sandi

python manage.py changepassword <user_name>
Obedient Osprey

Ubah Kata Sandi Django

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

Jawaban yang mirip dengan “Ubah Kata Sandi Django”

Pertanyaan yang mirip dengan “Ubah Kata Sandi Django”

Lebih banyak jawaban terkait untuk “Ubah Kata Sandi Django” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya