django create user programmatically code example

Example 1: django create user

from django.contrib.auth.models import User
user = User.objects.create_user(value['USERNAME'], value['EMAIL'], value['PASSWORD'])
user.first_name = value['NAME']
user.last_name = value['SURNAME']
user.save()

Example 2: how to create staff account in django

user = User.objects.create_user('john', '[email protected]', 'johnpassword')  
user.is_staff=True 
user.save()

Example 3: login views django template passing

path('accounts/login/', auth_views.LoginView.as_view(template_name='myapp/login.html')),