NoReverseMatch at /blog/ in django 2.0











up vote
1
down vote

favorite












am getting this error trying to set a blog category page
NoReverseMatch at /blog/
Reverse for 'category_detail' with arguments '('',)' not found. 1 pattern(s) tried: ['blog/category-detail/(?P[-a-zA-Z0-9_]+)$']



Here is my url.py






from django.urls import path,include
from .import views

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/<slug:slug>',views.post_detail,name="post_detail"),
path('blog/category-detail/<slug:slug>',views.category_detail,name="category_detail"),

]





views.py






from django.shortcuts import render,get_object_or_404
from.models import Post,Category

# Create your views here.
def post_list(request):
object_list=Post.objects.all()
context={
'object_list': object_list,
}
return render(request,"blog.html",context)

def post_detail(request,slug=None):
post=get_object_or_404(Post,slug=slug)
context={
'post':post,
}
return render(request,"post_detail.html",context)

def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(category=category,status='Published')
context={
'category':category,
'post':post,
}
return render(request,"category_detail.html",context)





blog.html






{% for obj in object_list %}
{% if obj.status == 'Published' %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{obj.title}}</h2>

<div>
{{obj.created}} Author {{obj.user}} <h4><a href="{% url 'category_detail' slug=post.category.slug %}">{{obj.Category}}</a></h4>
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}





category_detail.html






{% extends "base.html" %}
{% load static %}
{% block seo_title %}{{category.seo_title}}{% endblock %}
{% block seo_description %}{{category.seo_description}}{% endblock %}
{% block Content %}
<h2>{{category.title}}</h2>
<p>{{category.description}}</p>
{% for item in post %}
{{item.title}}
{{item.body|truncatechars:50}}
{% endfor %}
{% endblock Content %}





NOTE THE OTHER VIEWS.PY ARE WORKING FINE JUST THE category_detail function










share|improve this question






















  • As you are referencing obj you should change your url to {% url 'category-detail' obj.category.slug %}
    – Bidhan Majhi
    2 days ago















up vote
1
down vote

favorite












am getting this error trying to set a blog category page
NoReverseMatch at /blog/
Reverse for 'category_detail' with arguments '('',)' not found. 1 pattern(s) tried: ['blog/category-detail/(?P[-a-zA-Z0-9_]+)$']



Here is my url.py






from django.urls import path,include
from .import views

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/<slug:slug>',views.post_detail,name="post_detail"),
path('blog/category-detail/<slug:slug>',views.category_detail,name="category_detail"),

]





views.py






from django.shortcuts import render,get_object_or_404
from.models import Post,Category

# Create your views here.
def post_list(request):
object_list=Post.objects.all()
context={
'object_list': object_list,
}
return render(request,"blog.html",context)

def post_detail(request,slug=None):
post=get_object_or_404(Post,slug=slug)
context={
'post':post,
}
return render(request,"post_detail.html",context)

def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(category=category,status='Published')
context={
'category':category,
'post':post,
}
return render(request,"category_detail.html",context)





blog.html






{% for obj in object_list %}
{% if obj.status == 'Published' %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{obj.title}}</h2>

<div>
{{obj.created}} Author {{obj.user}} <h4><a href="{% url 'category_detail' slug=post.category.slug %}">{{obj.Category}}</a></h4>
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}





category_detail.html






{% extends "base.html" %}
{% load static %}
{% block seo_title %}{{category.seo_title}}{% endblock %}
{% block seo_description %}{{category.seo_description}}{% endblock %}
{% block Content %}
<h2>{{category.title}}</h2>
<p>{{category.description}}</p>
{% for item in post %}
{{item.title}}
{{item.body|truncatechars:50}}
{% endfor %}
{% endblock Content %}





NOTE THE OTHER VIEWS.PY ARE WORKING FINE JUST THE category_detail function










share|improve this question






















  • As you are referencing obj you should change your url to {% url 'category-detail' obj.category.slug %}
    – Bidhan Majhi
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











am getting this error trying to set a blog category page
NoReverseMatch at /blog/
Reverse for 'category_detail' with arguments '('',)' not found. 1 pattern(s) tried: ['blog/category-detail/(?P[-a-zA-Z0-9_]+)$']



Here is my url.py






from django.urls import path,include
from .import views

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/<slug:slug>',views.post_detail,name="post_detail"),
path('blog/category-detail/<slug:slug>',views.category_detail,name="category_detail"),

]





views.py






from django.shortcuts import render,get_object_or_404
from.models import Post,Category

# Create your views here.
def post_list(request):
object_list=Post.objects.all()
context={
'object_list': object_list,
}
return render(request,"blog.html",context)

def post_detail(request,slug=None):
post=get_object_or_404(Post,slug=slug)
context={
'post':post,
}
return render(request,"post_detail.html",context)

def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(category=category,status='Published')
context={
'category':category,
'post':post,
}
return render(request,"category_detail.html",context)





blog.html






{% for obj in object_list %}
{% if obj.status == 'Published' %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{obj.title}}</h2>

<div>
{{obj.created}} Author {{obj.user}} <h4><a href="{% url 'category_detail' slug=post.category.slug %}">{{obj.Category}}</a></h4>
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}





category_detail.html






{% extends "base.html" %}
{% load static %}
{% block seo_title %}{{category.seo_title}}{% endblock %}
{% block seo_description %}{{category.seo_description}}{% endblock %}
{% block Content %}
<h2>{{category.title}}</h2>
<p>{{category.description}}</p>
{% for item in post %}
{{item.title}}
{{item.body|truncatechars:50}}
{% endfor %}
{% endblock Content %}





NOTE THE OTHER VIEWS.PY ARE WORKING FINE JUST THE category_detail function










share|improve this question













am getting this error trying to set a blog category page
NoReverseMatch at /blog/
Reverse for 'category_detail' with arguments '('',)' not found. 1 pattern(s) tried: ['blog/category-detail/(?P[-a-zA-Z0-9_]+)$']



Here is my url.py






from django.urls import path,include
from .import views

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/<slug:slug>',views.post_detail,name="post_detail"),
path('blog/category-detail/<slug:slug>',views.category_detail,name="category_detail"),

]





views.py






from django.shortcuts import render,get_object_or_404
from.models import Post,Category

# Create your views here.
def post_list(request):
object_list=Post.objects.all()
context={
'object_list': object_list,
}
return render(request,"blog.html",context)

def post_detail(request,slug=None):
post=get_object_or_404(Post,slug=slug)
context={
'post':post,
}
return render(request,"post_detail.html",context)

def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(category=category,status='Published')
context={
'category':category,
'post':post,
}
return render(request,"category_detail.html",context)





blog.html






{% for obj in object_list %}
{% if obj.status == 'Published' %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{obj.title}}</h2>

<div>
{{obj.created}} Author {{obj.user}} <h4><a href="{% url 'category_detail' slug=post.category.slug %}">{{obj.Category}}</a></h4>
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}





category_detail.html






{% extends "base.html" %}
{% load static %}
{% block seo_title %}{{category.seo_title}}{% endblock %}
{% block seo_description %}{{category.seo_description}}{% endblock %}
{% block Content %}
<h2>{{category.title}}</h2>
<p>{{category.description}}</p>
{% for item in post %}
{{item.title}}
{{item.body|truncatechars:50}}
{% endfor %}
{% endblock Content %}





NOTE THE OTHER VIEWS.PY ARE WORKING FINE JUST THE category_detail function






from django.urls import path,include
from .import views

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/<slug:slug>',views.post_detail,name="post_detail"),
path('blog/category-detail/<slug:slug>',views.category_detail,name="category_detail"),

]





from django.urls import path,include
from .import views

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/<slug:slug>',views.post_detail,name="post_detail"),
path('blog/category-detail/<slug:slug>',views.category_detail,name="category_detail"),

]





from django.shortcuts import render,get_object_or_404
from.models import Post,Category

# Create your views here.
def post_list(request):
object_list=Post.objects.all()
context={
'object_list': object_list,
}
return render(request,"blog.html",context)

def post_detail(request,slug=None):
post=get_object_or_404(Post,slug=slug)
context={
'post':post,
}
return render(request,"post_detail.html",context)

def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(category=category,status='Published')
context={
'category':category,
'post':post,
}
return render(request,"category_detail.html",context)





from django.shortcuts import render,get_object_or_404
from.models import Post,Category

# Create your views here.
def post_list(request):
object_list=Post.objects.all()
context={
'object_list': object_list,
}
return render(request,"blog.html",context)

def post_detail(request,slug=None):
post=get_object_or_404(Post,slug=slug)
context={
'post':post,
}
return render(request,"post_detail.html",context)

def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(category=category,status='Published')
context={
'category':category,
'post':post,
}
return render(request,"category_detail.html",context)





{% for obj in object_list %}
{% if obj.status == 'Published' %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{obj.title}}</h2>

<div>
{{obj.created}} Author {{obj.user}} <h4><a href="{% url 'category_detail' slug=post.category.slug %}">{{obj.Category}}</a></h4>
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}





{% for obj in object_list %}
{% if obj.status == 'Published' %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{obj.title}}</h2>

<div>
{{obj.created}} Author {{obj.user}} <h4><a href="{% url 'category_detail' slug=post.category.slug %}">{{obj.Category}}</a></h4>
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}





{% extends "base.html" %}
{% load static %}
{% block seo_title %}{{category.seo_title}}{% endblock %}
{% block seo_description %}{{category.seo_description}}{% endblock %}
{% block Content %}
<h2>{{category.title}}</h2>
<p>{{category.description}}</p>
{% for item in post %}
{{item.title}}
{{item.body|truncatechars:50}}
{% endfor %}
{% endblock Content %}





{% extends "base.html" %}
{% load static %}
{% block seo_title %}{{category.seo_title}}{% endblock %}
{% block seo_description %}{{category.seo_description}}{% endblock %}
{% block Content %}
<h2>{{category.title}}</h2>
<p>{{category.description}}</p>
{% for item in post %}
{{item.title}}
{{item.body|truncatechars:50}}
{% endfor %}
{% endblock Content %}






javascript python html css django






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









Cipher

64




64












  • As you are referencing obj you should change your url to {% url 'category-detail' obj.category.slug %}
    – Bidhan Majhi
    2 days ago


















  • As you are referencing obj you should change your url to {% url 'category-detail' obj.category.slug %}
    – Bidhan Majhi
    2 days ago
















As you are referencing obj you should change your url to {% url 'category-detail' obj.category.slug %}
– Bidhan Majhi
2 days ago




As you are referencing obj you should change your url to {% url 'category-detail' obj.category.slug %}
– Bidhan Majhi
2 days ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













As the error said, the argument is missing here. Maybe you need to change {% url 'category_detail' slug=post.Category.slug %} with {% url 'category_detail' slug=obj.category.slug %} because I do not see any post variable reference in the blog.html template.



update



You have not shared your Model codes, but I am assuming your Post Model has Foreign Key to Category Model and it looks like Category=models.ForeignKey(Category). So you need to update the view like this:



def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(Category=category,status='Published')





share|improve this answer























  • Thanks worked but going to url localhost:8000/blog/category-detail/slug gives an error FieldError at /blog/category-detail/python Cannot resolve keyword 'category' into field. Choices are: Category, Category_id, body, created, id, seo_description, seo_title, slug, status, title, updated, user, user_id
    – Cipher
    yesterday










  • @Cipher updated the answer. Please have a look.
    – ruddra
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369086%2fnoreversematch-at-blog-in-django-2-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













As the error said, the argument is missing here. Maybe you need to change {% url 'category_detail' slug=post.Category.slug %} with {% url 'category_detail' slug=obj.category.slug %} because I do not see any post variable reference in the blog.html template.



update



You have not shared your Model codes, but I am assuming your Post Model has Foreign Key to Category Model and it looks like Category=models.ForeignKey(Category). So you need to update the view like this:



def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(Category=category,status='Published')





share|improve this answer























  • Thanks worked but going to url localhost:8000/blog/category-detail/slug gives an error FieldError at /blog/category-detail/python Cannot resolve keyword 'category' into field. Choices are: Category, Category_id, body, created, id, seo_description, seo_title, slug, status, title, updated, user, user_id
    – Cipher
    yesterday










  • @Cipher updated the answer. Please have a look.
    – ruddra
    yesterday















up vote
0
down vote













As the error said, the argument is missing here. Maybe you need to change {% url 'category_detail' slug=post.Category.slug %} with {% url 'category_detail' slug=obj.category.slug %} because I do not see any post variable reference in the blog.html template.



update



You have not shared your Model codes, but I am assuming your Post Model has Foreign Key to Category Model and it looks like Category=models.ForeignKey(Category). So you need to update the view like this:



def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(Category=category,status='Published')





share|improve this answer























  • Thanks worked but going to url localhost:8000/blog/category-detail/slug gives an error FieldError at /blog/category-detail/python Cannot resolve keyword 'category' into field. Choices are: Category, Category_id, body, created, id, seo_description, seo_title, slug, status, title, updated, user, user_id
    – Cipher
    yesterday










  • @Cipher updated the answer. Please have a look.
    – ruddra
    yesterday













up vote
0
down vote










up vote
0
down vote









As the error said, the argument is missing here. Maybe you need to change {% url 'category_detail' slug=post.Category.slug %} with {% url 'category_detail' slug=obj.category.slug %} because I do not see any post variable reference in the blog.html template.



update



You have not shared your Model codes, but I am assuming your Post Model has Foreign Key to Category Model and it looks like Category=models.ForeignKey(Category). So you need to update the view like this:



def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(Category=category,status='Published')





share|improve this answer














As the error said, the argument is missing here. Maybe you need to change {% url 'category_detail' slug=post.Category.slug %} with {% url 'category_detail' slug=obj.category.slug %} because I do not see any post variable reference in the blog.html template.



update



You have not shared your Model codes, but I am assuming your Post Model has Foreign Key to Category Model and it looks like Category=models.ForeignKey(Category). So you need to update the view like this:



def category_detail(request,slug=None):
category=get_object_or_404(Category,slug=slug)
post=Post.objects.filter(Category=category,status='Published')






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered 2 days ago









ruddra

7,98332546




7,98332546












  • Thanks worked but going to url localhost:8000/blog/category-detail/slug gives an error FieldError at /blog/category-detail/python Cannot resolve keyword 'category' into field. Choices are: Category, Category_id, body, created, id, seo_description, seo_title, slug, status, title, updated, user, user_id
    – Cipher
    yesterday










  • @Cipher updated the answer. Please have a look.
    – ruddra
    yesterday


















  • Thanks worked but going to url localhost:8000/blog/category-detail/slug gives an error FieldError at /blog/category-detail/python Cannot resolve keyword 'category' into field. Choices are: Category, Category_id, body, created, id, seo_description, seo_title, slug, status, title, updated, user, user_id
    – Cipher
    yesterday










  • @Cipher updated the answer. Please have a look.
    – ruddra
    yesterday
















Thanks worked but going to url localhost:8000/blog/category-detail/slug gives an error FieldError at /blog/category-detail/python Cannot resolve keyword 'category' into field. Choices are: Category, Category_id, body, created, id, seo_description, seo_title, slug, status, title, updated, user, user_id
– Cipher
yesterday




Thanks worked but going to url localhost:8000/blog/category-detail/slug gives an error FieldError at /blog/category-detail/python Cannot resolve keyword 'category' into field. Choices are: Category, Category_id, body, created, id, seo_description, seo_title, slug, status, title, updated, user, user_id
– Cipher
yesterday












@Cipher updated the answer. Please have a look.
– ruddra
yesterday




@Cipher updated the answer. Please have a look.
– ruddra
yesterday


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369086%2fnoreversematch-at-blog-in-django-2-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Saint-Aignan (Tarn-et-Garonne)

Volksrepublik China

How to test boost logger output in unit testing?