1user@hostname$ python3 -m django shell
2>>> import django.contrib.auth
3>>> User = django.contrib.auth.get_user_model()
4>>> user = User.objects.create_user('username', password='userpassword')
5>>> user.is_superuser = False
6>>> user.is_staff = False
7>>> user.save()
1from django.contrib.auth import authenticate, login
2
3def my_view(request):
4 username = request.POST['username']
5 password = request.POST['password']
6 user = authenticate(request, username=username, password=password)
7 if user is not None:
8 login(request, user)
9 # Redirect to a success page.
10 ...
11 else:
12 # Return an 'invalid login' error message.
13 ...
14
1from django.contrib.auth.mixins import LoginRequiredMixin
2
3LOGIN_URL = 'your_url'
1from django.contrib.auth.models import User
2user = User.objects.create_user(value['USERNAME'], value['EMAIL'], value['PASSWORD'])
3user.first_name = value['NAME']
4user.last_name = value['SURNAME']
5user.save()