При переходе на главную страницу возникает ошибка NoReverseMatch at /
Reverse for 'blogtemplate-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['blogtemplates/(?P[-a-zA-Z0-9_]+)/\\Z'].
views.py
class BlogTemplateDetailView(DetailView):
model = BlogTemplate
# queryset = BlogTemplate.objects.get(id=id)
template_name = 'blogtemplate-detail.html'
slug_url_kwarg = 'blogtemplates_slug'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['blog_list'] = BlogTemplate.objects.all()
# context['blog_list'] = BlogTemplate.objects.get(id=id)
return context
urls.py
path('blogtemplates/<slug:blogtemplates_slug>/', views.BlogTemplateDetailView.as_view(), name='blogtemplate-detail'),
В шаблоне blogtemplate-detail.html
<h4><a href="{% url 'element_one:blogtemplate-detail' blogtemplates.slug %}"></a></h4>
модель
class BlogTemplate(models.Model):
objects = models.Manager()
date = models.DateField(auto_now=True)
author_name = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=300)
blog_context = models.TextField()
comment = models.ForeignKey('Comment', on_delete=models.SET_NULL, null=True)
slug = models.SlugField(unique=True)