Home > Enterprise >  How do I fix this Getting no reverse match error in django
How do I fix this Getting no reverse match error in django

Time:10-03

I have been facing this issue. And I have a url name post-page-detail but then also getting error please See the error screenshot below. error screen shot

My singlepost.html html page

<a href="{% url "post-detail-page" slug=post.slug %}">
    <h2>{{post.tractor_company}} || {{post.tractor_model}}</h2>
<pre><h5>{{post.implimentaion}}</h5>
{{post.farmer}}
Uplode Date : {{post.date}}</pre>
</a>
</div>

URLs.py

from . import views
urlpatterns = [
    path("",views.starting_page,name = "starting-page"),
    path("posts",views.posts,name = "post-page"),
    path("posts/<slug:slug>",views.post_detail,name="post-detail-page"),
]

View.py

from django import forms
from django.contrib.auth.models import User
from django.shortcuts import render, redirect ,get_object_or_404
from .models import Post, Farmer
# Create your views here.
from django.http import HttpResponseRedirect 
# Create your views here.
def starting_page(request):
    return render(request,"tractor/index.html")

def posts(request):
    qs = Post.objects.all()  
    context = {"posts":qs}
    return render(request,"tractor/all-post.html",context)
    
def add_post(request):
    pass


def post_detail(request,slug):
    indentified_post = get_object_or_404(Post,slug=slug)
    return render(request,"blog/post-detail.html",{'post':indentified_post})

i am iterating through posts and using the post-detail.html page

all-post.html.

{% load static %}

{% block title %}
All Tractors
{% endblock  %}

{% block content%}
<section id="all_events">
    <br>
    <h1 style="text-align:center;">All Tractors</h1>
    <ul>
      {% for post in posts %}
        <br>
        {% include "tractor/includes/singlePost.html" %}
      {% endfor %}
    </ul>

</section>
{% endblock %}

Root urls.py

from django.urls import path,include
urlpatterns = [
    path('admin/', admin.site.urls),
    path("",include(("tractor.urls","tractor"))),
]

CodePudding user response:

The 'tractor' part in the path('', include(('tractor.urls', 'tractor'))) in the include(…) function [Django-doc] specifies the app_namespace. This means that for all URLs you use in the tractor.urls urls, you should prefix this with tractor::

<a href="{% url 'tractor:post-detail-page' slug=post.slug %}">
    …
</a>
  • Related