-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51b23cb
commit ccb73bf
Showing
1 changed file
with
3 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
from django.shortcuts import render, redirect | ||
from django.urls import reverse | ||
from django.shortcuts import render | ||
from main.models import Forum | ||
|
||
def search_forum(request): | ||
query = request.GET.get('search', '') # Obtém o parâmetro de pesquisa da URL | ||
if query: | ||
try: | ||
forum = Forum.objects.get(title__icontains=query) # Busca o fórum que contém o texto da pesquisa | ||
return redirect(reverse('forum_detail', args=[forum.id])) # Redireciona para a página do fórum | ||
except Forum.DoesNotExist: | ||
return render(request, 'search/not_found.html', {'query': query}) # Página de não encontrado | ||
return redirect('forum_list') | ||
forums = Forum.objects.filter(title__icontains=query) # Filtra os fóruns com base na pesquisa | ||
return render(request, 'main/forums.html', {'forums': forums, 'query': query}) # Renderiza a página de fóruns com os resultados |