Can solve this error ? ( NoReverseMatch )

I'm ratherly amatour in django and cant solve this problem,

error: NoReverseMatch at /blog/

Reverse for 'single' with keyword arguments '{'pid': ''}' not found. 1 pattern(s) tried: \['blog/(?P\<pid\>\[0-9\]+)\\Z'\] :

from django.urls import path
from blog.views import \*
from django.conf.urls.static import static

app_name= 'blog'

urlpatterns = \[
path('\<int:pid\>',single, name='single'),
\] :

from django.shortcuts import render
from blog.models import Post
import datetime

def single(request,pid):
single_post= Post.objects.filter(pk=pid)  
def counting_single_views(n):
n.counted_views += 1
context = {'single_post':single_post}
return render(request,'blog/blog-single.html',context)

def home(request):

now =
posts= Post.objects.filter(published_date__lte= now)
return render(request,'blog/blog-home.html',context)

blog-home.html :

{% for post in posts %}
\<a href="{% url 'blog:single' %}"\>\<h3\>{{post.title}}\</h3\>\</a\>
\<p class="excert"\>
{% endfor %}

i tried with id instead of pk , but no differ,

In your url file

path('\<int:pid\>',single, name='single'),

Replace it with

path('<int:pid>',single, name='single'),

and also note [#Manoj Kamble] point that can also happen

i got my answer, infact i didn't change any of url tag, i used

 {% url 'blog:single' %}

but in 'base.html' used

{% url 'blog:single' %} 

i changed this and NoReverseMatch solved. thanks everyone.

Back to Top