Возникла ошибка Django NoReverseMatch at ... Reverse for 'profile_list' not found. 'profile_list' is not a valid view function or pattern name

Рейтинг: 0Ответов: 1Опубликовано: 16.05.2023

Пытаюсь сделать поиск в django приложении. Выдаёт ошибку

NoReverseMatch at /profile_list/
Reverse for 'profile_list' not found.
'profile_list' is not a valid view function or pattern name.

html файл

{% extends 'base.html' %}

{% block content %}

<form action="{% url 'profile_list' %}" method="get">
  <input name="search" type="text" placeholder="Search...">
</form>

<div class="column">


{% for profile in profiles %}

<div class="block">
  <div class="card">
    <a href="{% url 'dwitter:profile' profile.id %}">
    <div class="card-content">
      <div class="media">
        <div class="media-left">
          <figure class="image is-48x48">
            <img src="https://bulma.io/images/placeholders/96x96.png"
                 alt="Placeholder image">
          </figure>
        </div>
        <div class="media-content">
          <p class="title is-4">{{ profile.name }}</p>
          <p class="subtitle is-6">@{{ profile.user.username|lower }}</p>
          <p class="subtitle is-6">{{ profile.nap|lower }}</p>
          <p class="subtitle is-6">{{ profile.curse|lower }}</p>
          <p class="subtitle is-6">{{ profile.raiting|lower }}</p>
        </div>
      </div>
    </div>
    </a>
  </div>
</div>

{% endfor %}

</div>

{% endblock content %}```

urls.py

from django.urls import path
from .views import dashboard, profile_list, profile

app_name = "dwitter"

urlpatterns = [
    path("", dashboard, name="dashboard"),
    path("profile_list/", profile_list, name="profile_list"),
    path("profile/<int:pk>", profile, name="profile"),
]

views.py

def profile_list(request):
    profiles = Profile.objects.exclude(user=request.user)
    query = request.GET.get('search','')

    if query:
         Profile.objects.filter (Q(name__icontains=query) | Q(nap__icontains=query))
    else: Profile.objects.all

    return render(request, "dwitter/profile_list.html", {"profile_list": profiles})

Ответы

▲ 0

В моём случае нужно было просто дописать <form action="{% url 'dwitter:profile_list' %}" method="get">