authentication in django code example
Example 1: django import user
from django.contrib.auth.models import User
Example 2: django login
from django.contrib.auth import authenticate, login
def my_view(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
...
else:
...
Example 3: how to create staff account in django
user = User.objects.create_user('john', '[email protected]', 'johnpassword')
user.is_staff=True
user.save()
Example 4: login views django template passing
path('accounts/login/', auth_views.LoginView.as_view(template_name='myapp/login.html')),