1👍
Have a look at your variable names, you are using cat
to get the title and category
to get the pk. Maybe category
is undefined? This will result in an empty string inserted in the url tag and would lead to the received error message.
1👍
The name of the parameter in your urls.py
is pk
:
url(r'^category/(?P<pk>[0-9]+)/$', views.category_detail, name='category'),
But you are trying to find url with parameter category_id
. Change it to:
{% url 'blog.views.category_detail' pk=category.pk %}
Or even omit the name of parameter:
{% url 'blog.views.category_detail' category.pk %}
And imho, as far as your url has a name
, it is better to find this url by it’s name instead of view’s name:
{% url 'category' category.pk %}
UPDATE: In the post_list.html
you use this code:
<a href="{% url 'category_detail' pk=category.pk %}/">{{ cat.title }}</a>
As far as I understand the category variable is named cat
. Yous should pass the correct variable to the {% url %}
tag:
<a href="{% url 'category_detail' pk=cat.pk %}">{{ cat.title }}</a>
To solve such problems once and forever consider to implement the get_absolute_url()
method in your Category
model. Use this method any time you need to point to the category:
<a href="{{ cat.get_absolute_url }}">{{ cat.title }}</a>