hello, I have a problem using my django application, I have two apps, two views and tamplates. I want to implement filters on the results of a query, but I am directly redirected to the logout page.
I share my files with you.
my first view
from django.shortcuts import render
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from .models import datalog
from .filtre import *
#from django.contrib.auth.decorators import login_required
#@login_required (login_url='login')
# Create your views here.
def HomeLog(request):
current_user= request.user
log = datalog.objects.all()
monfiltre= logFilter(request.GET,queryset=log )
log=monfiltre.qs
paginator = Paginator(log, 10) # Affichez 10 tickets par page
# Récupérez le numéro de la page à partir de la requête, par défaut à la première page
page = request.GET.get('page')
try:
log = paginator.page(page)
except PageNotAnInteger:
# Si la page n'est pas un entier, fournissez la première page
log = paginator.page(1)
except EmptyPage:
# Si la page est hors limites (par exemple, 9999), fournissez la dernière page
log = paginator.page(paginator.num_pages)
context={'log':log,'current_user':current_user,'monfiltre':monfiltre}
return render(request,'log/acceuil.html', context)
ma user view
from django.shortcuts import render,redirect
from django.contrib.auth import authenticate,login,logout
from django.contrib import messages
# Create your views here.
def login_user(request):
if request.method == "POST":
username = request.POST["username"]
password = request.POST["password"]
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('list')
else:
messages.error(request,("Profil ou mot de passe incorect"))
return render(request, 'registration/login.html')
else:
return render(request, 'registration/login.html')
def logout_user(request):
logout(request)
messages.error(request,("Deconnexion réussi"))
return redirect('login')
my tamplate
{% extends 'base/main.html' %}
{% block content %}
<div class="container-fluid">
<div class="row ">
<div class="col-sm">
<div class="card card-body">
<form method="get">
{{monfiltre.form}}
<button class="btn btn-primary" btn-sm>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-filter" viewBox="0 0 16 16">
<path d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/>
</svg>
FILTRER
</button>
</form>
</div>
</div>
<div>
<table class="table">
<div class="card- card-body">
<thead>
<tr>
<th scope="col">Date</th>
<th scope="col">Heure</th>
<th scope="col">Utilisateur</th>
<th scope="col">Opération</th>
<th scope="col">Action</th>
<th scope="col">Numéro de compte</th>
<th scope="col">Montant</th>
</tr>
</thead>
<tbody>
{% for log in log %}
<tr>
<th>{{log.date_eve|date:"d/m/Y"}}</th>
<td>{{log.heure}}</td>
<td>{{log.utilisateur}}</td>
<td>{{log.operation}}</td>
<th>{{log.libelle}}</th>
<td>{{log.compte}}</td>
<td>{{log.montant}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="container">
<div class="row my-5">
<div class="col-md-4 offset-md-5">
<p> Page: {{ log.number }} /{{ log.paginator.num_pages }}</p>
<nav aria-label="Page navigation example">
<ul class="pagination">
{% if log.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ log.previous_page_number }}">Previous</a></li>
{% endif %}
{% if log.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ log.next_page_number}}">Next</a></li>
{% endif %}
</ul>
</nav>
</div>
</div>
</div>
</div>
{% endblock %}