Currently, I am learning Django and with it, I am building a nonprofit organization's website. It is almost like a blog website except for like, comment features. Anyways, here's a page where all the reports are listed and these have tags. I used Django-taggit. I followed through a tutorial to show the tags and make it clickable and filter by tags - but I am running into the following error:

error1

error2

Here are my relevent model, view, app/url and template files:

from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from taggit.managers import TaggableManager

class Report(models.Model):
    rp_title = models.CharField(max_length=500)
    slug = models.SlugField(max_length=300, unique_for_date='date')
    url = models.URLField(max_length=500)
    date = models.DateTimeField(default=timezone.now)
    rp_tags = TaggableManager()

    # rp_body = models.TextField()

    def __str__(self):
        return self.rp_title

    class Meta:
        ordering = ('rp_title',)

    def get_absolute_url(self):
        return reverse('report:report_detail', args=[self.slug])


class ReportListView(ListView):
    model = Report
    queryset = Report.objects.all()
    context_object_name = 'reports'
    template_name = 'blog/report_list.html'


class ReportTagView(ListView):
    model = Report
    context_object_name = 'reports'
    template_name = 'blog/report_list.html'

    def get_queryset(self):
        return Report.objects.filter(tags__slug=self.kwargs.get('tag_slug'))
<div class="sidebar__single sidebar__tags">
                            <h3 class="sidebar__title">Tags</h3>
                            <div class="sidebar__tags-list">
                                {% for tag in report.rp_tags.all %}
                                    <a href="{% url 'blog:report_tag' tag.slug %}"
                                       class="link-light text-decoration-none badge bg-secondary">
                                        {{ tag.name }}
                                    </a>

                                {% endfor %}
                            </div>
                        </div>
app_name = 'blog'
urlpatterns = [
    # post views

    path('', Home.as_view(), name='home'),
    
    path('projects/<slug:slug>/', ProjectDetailView.as_view(), name='project_detail'),
    path('reports/', ReportListView.as_view(), name='report_list'),
    path('report/<slug:slug>/', ReportDetailView.as_view(), name='report_detail'),
    # path('report/<int:year>/', ReportYearArchiveView.as_view(), name="report_year_archive"),
    path('taggit/tag/<slug:tag_slug>/', ReportTagView.as_view(), name='report_tag'),
    path('news/', NewsListView.as_view(), name='news_list'),
    path('news/<slug:slug>/', NewsDetailView.as_view(), name='news_detail'),
    path('taggit/tag/<slug:rp_tags>/', NewsListView.as_view(), name='post_tag'),
    
]

What I don't understand is that I did not write "tags" anywhere so I can't trace the error back, and for my CBV I cannot make the filter by tags option work. It would be great if you could point out what I am missing here. My Django version is 3.2.7 and Taggit version is 3.0.0

Thank you so much.

I tried tutorials on Django-taggit, followed through but my tags click and filter are not working.

0

There are 0 best solutions below