“Django Cambiar contraseña” Código de respuesta

Djanog shell cambia contraseña

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

Vista de cambio de contraseña de Django

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 cambia la contraseña del usuario

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 Cambiar contraseña

python manage.py changepassword <user_name>
Obedient Osprey

Cambiar contraseña django

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

Respuestas similares a “Django Cambiar contraseña”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código