problems with login

authorization doesn’t work

views.py

from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.template import loader
from .models import Movie
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth import login, logout
def log_in(request):

    if request.method == 'POST':
        form = AuthenticationForm(request.POST)
        if form.is_valid():
            user = form.get_user()
            login(request, user)
            return redirect('main')
        else:
             print(form.errors)
    else:
        form = AuthenticationForm()
        print(form.errors)
    
    context = {
        'form': form,
    }
    return render(request, 'log_in.html', context)

urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('', views.main, name='main'),
    path('movies/', views.movies, name='movies'),
    path('sign_up/', views.sign_up, name='sign_up'),
    path('log_in/', views.log_in, name='log_in'),
]

log_in.html

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Log In</title>
    <link rel="stylesheet" href="{% static 'log_in.css' %}">
    <script src="{% static 'log_in.js' %}"></script>
</head>
<body>
    <form method="POST">
        {% csrf_token %}
        <h1>Log In</h1>
        {{form.username}}
        {{form.password}}
        <input type="submit" name="Log In">
        {% if form.errors %}
            <p>{{ form.errors }}</p>
        {% endif %}
    </form>
    <img  src="{% static 'arrow.png' %}" alt="arrow">
</body>
</html>

My first suggestion is that you review the docs at Authentication Views to see if you can use the standard LoginView. That’s the easiest way to handle this.

I also suggest you take a look at the standard LoginView in django.contrib.auth.views to see how Django performs the login process. Calling get_user on the submitted form is not sufficient. If you want to handle this yourself, see Using the Django authentication system | Django documentation | Django