Could someone check out my code error please?

Hello, could someone take a look at my code please? My login button return NONE and I am lost with it since 2 days.

The views:

def login_view(request, *args, **kwargs):
    context = {}

    user = request.user
    if user.is_authenticated: 
        return redirect("index")

    destination = get_redirect_if_exists(request)
    print("destination: " + str(destination))

    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            user = authenticate(email=email, password=password)

            if user:
                login(request, user)
                if destination: # si destination n'est None
                    return redirect(destination)
                return redirect("index")

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form

    return render(request, "login.html", context)


def get_redirect_if_exists(request):
    redirect = None
    if request.GET:
        if request.GET.get("next"):
            redirect = str(request.GET.get("next"))
    return redirect

The root_urls:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include("vazimba.urls")),
    path('account/', include("account.urls")),

]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)

The_app_urls:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

from .views import register_view, login_view, logout_view

urlpatterns = [

    path('login/', login_view, name="login"),
    path('logout/', logout_view, name="logout"),
    path('register/', register_view, name="register"),

The templates: ==> account(the app) => templates/account/login.html

    {% if user.is_authenticated %}
        # html code-----
    {% else %}

<div class="container">
    <h1>home page</h1>

    <h2>Vous vous êtes bien déconnecté, à bientôt!</h2>

    <a href="{% url 'login' %}" class="btn btn-sm btn-primary">Login</a>
</div>


{% endif %}

When I click on the login button, nothing happens then it should redirect me to the login template, right? Thank you in forwards!!!

place {% url 'your_app_name:login' %} instead {% url 'login' %}

Back to Top