“Django Kata Sandi Perubahan Tampilan” 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 mengubah 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 “Django Kata Sandi Perubahan Tampilan”

Pertanyaan yang mirip dengan “Django Kata Sandi Perubahan Tampilan”

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

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya