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 %}
python django
add a comment |
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 %}
python django
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
add a comment |
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 %}
python django
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
python django
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
add a comment |
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
add a comment |
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>
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 addobj.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 toblog/post-detail/<slug:slug>
. thelocalhost:8000/blog/post-detail
will no longer a valid url. To see a post details, you need to add the slug of the post. solocalhost:8000/blog/post-detail/post-slug
– Lemayzeur
Nov 18 at 21:34
add a comment |
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>
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 addobj.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 toblog/post-detail/<slug:slug>
. thelocalhost:8000/blog/post-detail
will no longer a valid url. To see a post details, you need to add the slug of the post. solocalhost:8000/blog/post-detail/post-slug
– Lemayzeur
Nov 18 at 21:34
add a comment |
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>
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 addobj.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 toblog/post-detail/<slug:slug>
. thelocalhost:8000/blog/post-detail
will no longer a valid url. To see a post details, you need to add the slug of the post. solocalhost:8000/blog/post-detail/post-slug
– Lemayzeur
Nov 18 at 21:34
add a comment |
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>
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>
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 addobj.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 toblog/post-detail/<slug:slug>
. thelocalhost:8000/blog/post-detail
will no longer a valid url. To see a post details, you need to add the slug of the post. solocalhost:8000/blog/post-detail/post-slug
– Lemayzeur
Nov 18 at 21:34
add a comment |
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 addobj.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 toblog/post-detail/<slug:slug>
. thelocalhost:8000/blog/post-detail
will no longer a valid url. To see a post details, you need to add the slug of the post. solocalhost: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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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