models.py
class News(models.Model):
title = models.CharField(max_length = 30, verbose_name = 'Заголовок')
content = models.TextField(verbose_name = 'Контент')
picture = models.ImageField(upload_to = 'pictures/News', default = 'null', null = True, blank = True, verbose_name = 'Картинка')
published = models.DateField(auto_now_add = True, db_index = True, verbose_name = 'Дата')
rubric = models.ForeignKey('Rubric', default = 'Без рубрики', on_delete = models.PROTECT, verbose_name = 'Рубрика')
def __str__(self):
return self.title
class Meta:
verbose_name_plural = 'Новости'
verbose_name = 'Новости'
ordering = ['-published']
views.py:
class Search(ListView):
paginate_by = 3
def get_queryset(self):
return News.objects.filter(title__icontains = self.request.GET.get("q"))
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context["q"] = self.request.GET.get("q")
return context
urls.py
urlpatterns = [
...
path('search/', views.Search.as_view(), name = 'search')
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Форма
<form method="get", action = "{% url 'search' %}">
<input type="search" placeholder="Введите название статьи" name="search" class="form-control">
<button class = "btn btn-success" type = "sumbit"> Отправить </button>
</form>
В итоге такая ошибка: