2007年3月30日 星期五

Creating a new user at django


Creating users


The most basic way to create users is to use the create_user helper
function that comes with Django:

>>> 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 ready to be saved
# to the database. You can continue to change its attributes
# if you want to change other fields.
>>> user.is_staff = True
>>> user.save()


Changing passwords


Change a password with set_password():

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

Don’t set the password attribute directly unless you know what you’re
doing. This is explained in the next section.

 powered by clipmarksblog it

沒有留言: