1>>> from django.contrib.auth.models import User
2>>> user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
3
4# At this point, user is a User object that has already been saved
5# to the database. You can continue to change its attributes
6# if you want to change other fields.
7>>> user.last_name = 'Lennon'
8>>> user.save()
9
1from django.contrib.auth.mixins import LoginRequiredMixin
2
3LOGIN_URL = 'your_url'
1def sample_view(request):
2 current_user = request.user
3 print current_user.id
1if request.user.is_authenticated:
2 # Do something for authenticated users.
3else:
4 # Do something for anonymous users.