No Post matches the given query.in django











up vote
0
down vote

favorite












am using django 2.0 and here is the problem
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/blog/post-detail/
Raised by: blog.views.post_detail
No Post matches the given query.



here is the blog/urls






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

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/',views.post_detail,name="post_detail"),

]





and views.py






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

# 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)





and the post_detail.html






{% extends "base.html" %}
{% load static %}
{% block seo_title %}{% endblock %}
{% block seo_description %}{% endblock %}
{% block Content %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{post.title}}</h2>
<div>
{{post.created}} Author {{Post.user}}
<hr/>
<p>{{post.body}}</p>
</article>

{% endblock Content %}





CAN ANYONE HELP ON THIS THE ONLY PROBLEM I SEE THAT SLUG THING I MUST HAVE CONFUSED SOMEWHERE
blog.html






<!-- Blog -->
<div class="blog">
<div class="row">
<div class="col-sm-8">

<!-- Blog Post-->
{% 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}}
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' slug= post.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}












share|improve this question
























  • You don't seem to have a slug parameter in your detail URL.
    – Daniel Roseman
    Nov 18 at 20:51










  • still gives page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:23















up vote
0
down vote

favorite












am using django 2.0 and here is the problem
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/blog/post-detail/
Raised by: blog.views.post_detail
No Post matches the given query.



here is the blog/urls






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

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/',views.post_detail,name="post_detail"),

]





and views.py






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

# 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)





and the post_detail.html






{% extends "base.html" %}
{% load static %}
{% block seo_title %}{% endblock %}
{% block seo_description %}{% endblock %}
{% block Content %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{post.title}}</h2>
<div>
{{post.created}} Author {{Post.user}}
<hr/>
<p>{{post.body}}</p>
</article>

{% endblock Content %}





CAN ANYONE HELP ON THIS THE ONLY PROBLEM I SEE THAT SLUG THING I MUST HAVE CONFUSED SOMEWHERE
blog.html






<!-- Blog -->
<div class="blog">
<div class="row">
<div class="col-sm-8">

<!-- Blog Post-->
{% 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}}
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' slug= post.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}












share|improve this question
























  • You don't seem to have a slug parameter in your detail URL.
    – Daniel Roseman
    Nov 18 at 20:51










  • still gives page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:23













up vote
0
down vote

favorite









up vote
0
down vote

favorite











am using django 2.0 and here is the problem
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/blog/post-detail/
Raised by: blog.views.post_detail
No Post matches the given query.



here is the blog/urls






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

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/',views.post_detail,name="post_detail"),

]





and views.py






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

# 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)





and the post_detail.html






{% extends "base.html" %}
{% load static %}
{% block seo_title %}{% endblock %}
{% block seo_description %}{% endblock %}
{% block Content %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{post.title}}</h2>
<div>
{{post.created}} Author {{Post.user}}
<hr/>
<p>{{post.body}}</p>
</article>

{% endblock Content %}





CAN ANYONE HELP ON THIS THE ONLY PROBLEM I SEE THAT SLUG THING I MUST HAVE CONFUSED SOMEWHERE
blog.html






<!-- Blog -->
<div class="blog">
<div class="row">
<div class="col-sm-8">

<!-- Blog Post-->
{% 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}}
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' slug= post.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}












share|improve this question















am using django 2.0 and here is the problem
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/blog/post-detail/
Raised by: blog.views.post_detail
No Post matches the given query.



here is the blog/urls






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

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/',views.post_detail,name="post_detail"),

]





and views.py






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

# 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)





and the post_detail.html






{% extends "base.html" %}
{% load static %}
{% block seo_title %}{% endblock %}
{% block seo_description %}{% endblock %}
{% block Content %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{post.title}}</h2>
<div>
{{post.created}} Author {{Post.user}}
<hr/>
<p>{{post.body}}</p>
</article>

{% endblock Content %}





CAN ANYONE HELP ON THIS THE ONLY PROBLEM I SEE THAT SLUG THING I MUST HAVE CONFUSED SOMEWHERE
blog.html






<!-- Blog -->
<div class="blog">
<div class="row">
<div class="col-sm-8">

<!-- Blog Post-->
{% 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}}
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' slug= post.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}








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

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/',views.post_detail,name="post_detail"),

]





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

urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/',views.post_detail,name="post_detail"),

]





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

# 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)





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

# 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)





{% extends "base.html" %}
{% load static %}
{% block seo_title %}{% endblock %}
{% block seo_description %}{% endblock %}
{% block Content %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{post.title}}</h2>
<div>
{{post.created}} Author {{Post.user}}
<hr/>
<p>{{post.body}}</p>
</article>

{% endblock Content %}





{% extends "base.html" %}
{% load static %}
{% block seo_title %}{% endblock %}
{% block seo_description %}{% endblock %}
{% block Content %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">

<h2>{{post.title}}</h2>
<div>
{{post.created}} Author {{Post.user}}
<hr/>
<p>{{post.body}}</p>
</article>

{% endblock Content %}





<!-- Blog -->
<div class="blog">
<div class="row">
<div class="col-sm-8">

<!-- Blog Post-->
{% 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}}
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' slug= post.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}





<!-- Blog -->
<div class="blog">
<div class="row">
<div class="col-sm-8">

<!-- Blog Post-->
{% 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}}
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' slug= post.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}






python django






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 20:49









Daniel Roseman

439k40571626




439k40571626










asked Nov 18 at 20:42









Cipher

64




64












  • You don't seem to have a slug parameter in your detail URL.
    – Daniel Roseman
    Nov 18 at 20:51










  • still gives page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:23


















  • You don't seem to have a slug parameter in your detail URL.
    – Daniel Roseman
    Nov 18 at 20:51










  • still gives page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:23
















You don't seem to have a slug parameter in your detail URL.
– Daniel Roseman
Nov 18 at 20:51




You don't seem to have a slug parameter in your detail URL.
– Daniel Roseman
Nov 18 at 20:51












still gives page not found The current path, blog/post-detail/, didn't match any of these.
– Cipher
Nov 18 at 21:23




still gives page not found The current path, blog/post-detail/, didn't match any of these.
– Cipher
Nov 18 at 21:23












1 Answer
1






active

oldest

votes

















up vote
0
down vote













The view post_detail(request,slug=None) is to view details about a post. So your URL pattern is incorrect:



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


To call it in templates, the simpler and correct way to do is:



<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>





share|improve this answer





















  • I have added that line and here is the error page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:19










  • did you add obj.slug in URL?
    – Lemayzeur
    Nov 18 at 21:25












  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • If you have changed your url pattern to blog/post-detail/<slug:slug>. the localhost:8000/blog/post-detail will no longer a valid url. To see a post details, you need to add the slug of the post. so localhost:8000/blog/post-detail/post-slug
    – Lemayzeur
    Nov 18 at 21:34













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%2f53365255%2fno-post-matches-the-given-query-in-django%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













The view post_detail(request,slug=None) is to view details about a post. So your URL pattern is incorrect:



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


To call it in templates, the simpler and correct way to do is:



<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>





share|improve this answer





















  • I have added that line and here is the error page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:19










  • did you add obj.slug in URL?
    – Lemayzeur
    Nov 18 at 21:25












  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • If you have changed your url pattern to blog/post-detail/<slug:slug>. the localhost:8000/blog/post-detail will no longer a valid url. To see a post details, you need to add the slug of the post. so localhost:8000/blog/post-detail/post-slug
    – Lemayzeur
    Nov 18 at 21:34

















up vote
0
down vote













The view post_detail(request,slug=None) is to view details about a post. So your URL pattern is incorrect:



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


To call it in templates, the simpler and correct way to do is:



<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>





share|improve this answer





















  • I have added that line and here is the error page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:19










  • did you add obj.slug in URL?
    – Lemayzeur
    Nov 18 at 21:25












  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • If you have changed your url pattern to blog/post-detail/<slug:slug>. the localhost:8000/blog/post-detail will no longer a valid url. To see a post details, you need to add the slug of the post. so localhost:8000/blog/post-detail/post-slug
    – Lemayzeur
    Nov 18 at 21:34















up vote
0
down vote










up vote
0
down vote









The view post_detail(request,slug=None) is to view details about a post. So your URL pattern is incorrect:



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


To call it in templates, the simpler and correct way to do is:



<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>





share|improve this answer












The view post_detail(request,slug=None) is to view details about a post. So your URL pattern is incorrect:



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


To call it in templates, the simpler and correct way to do is:



<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 at 20:51









Lemayzeur

5,1021733




5,1021733












  • I have added that line and here is the error page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:19










  • did you add obj.slug in URL?
    – Lemayzeur
    Nov 18 at 21:25












  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • If you have changed your url pattern to blog/post-detail/<slug:slug>. the localhost:8000/blog/post-detail will no longer a valid url. To see a post details, you need to add the slug of the post. so localhost:8000/blog/post-detail/post-slug
    – Lemayzeur
    Nov 18 at 21:34




















  • I have added that line and here is the error page not found The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:19










  • did you add obj.slug in URL?
    – Lemayzeur
    Nov 18 at 21:25












  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
    – Cipher
    Nov 18 at 21:32










  • If you have changed your url pattern to blog/post-detail/<slug:slug>. the localhost:8000/blog/post-detail will no longer a valid url. To see a post details, you need to add the slug of the post. so localhost:8000/blog/post-detail/post-slug
    – Lemayzeur
    Nov 18 at 21:34


















I have added that line and here is the error page not found The current path, blog/post-detail/, didn't match any of these.
– Cipher
Nov 18 at 21:19




I have added that line and here is the error page not found The current path, blog/post-detail/, didn't match any of these.
– Cipher
Nov 18 at 21:19












did you add obj.slug in URL?
– Lemayzeur
Nov 18 at 21:25






did you add obj.slug in URL?
– Lemayzeur
Nov 18 at 21:25














Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
– Cipher
Nov 18 at 21:32




Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
– Cipher
Nov 18 at 21:32












Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
– Cipher
Nov 18 at 21:32




Yes i adde it for the part continue leading it works fine fine but trying to access this url localhost:8000/blog/post-detail gives an error The current path, blog/post-detail/, didn't match any of these.
– Cipher
Nov 18 at 21:32












If you have changed your url pattern to blog/post-detail/<slug:slug>. the localhost:8000/blog/post-detail will no longer a valid url. To see a post details, you need to add the slug of the post. so localhost:8000/blog/post-detail/post-slug
– Lemayzeur
Nov 18 at 21:34






If you have changed your url pattern to blog/post-detail/<slug:slug>. the localhost:8000/blog/post-detail will no longer a valid url. To see a post details, you need to add the slug of the post. so localhost:8000/blog/post-detail/post-slug
– Lemayzeur
Nov 18 at 21:34




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365255%2fno-post-matches-the-given-query-in-django%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

Costa Masnaga

Fotorealismo

Sidney Franklin