Monday, November 10, 2014

The core of django authentication

You can find nice information here:
https://docs.djangoproject.com/en/dev/topics/auth/

and here:
https://docs.djangoproject.com/en/dev/topics/auth/default/

There is a lot to learn.  But for me the core of it is this:
  1. authentication comes built in by default with simple user objects that include username, password, and email
  2. if you have a username, a password, and an email address, you can set up a new user using
    from django.contrib.auth.models import User
    >>> user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword') 
  3.  you can check the identity of a user in a view that receives a post request using
    from django.contrib.auth import authenticate
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)

No comments:

Post a Comment