Herramientas de usuario

Herramientas del sitio


fw:djangoadv

¡Esta es una revisión vieja del documento!


Advanced Django

Authentication

Use of the user model

There is only one class in Django which is User, different types of users are instances of this class with other special attributes set.
Main attributes are: username, password, email, first_name, and last_name. However, there are others.
You can create users by code:

from django.contrib.auth.models import User
user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
# At this point, user is a User object that has already been saved to the database. 
user.last_name = 'Lennon'
user.save()

To change user passwords we'll do:

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

Authorization

Customizing authorization

fw/djangoadv.1401527156.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)