Noreversematch at /blog/ | in a Django app

Asked

Viewed 21 times

0

good afternoon. First of all, this is my first question on stack overflow. So I apologize if it’s too vague.

I started to study djnago in the last days and I came across the following mistake: Noreversematch. inserir a descrição da imagem aqui From what I could understand this related to my urlpatterns, but I cannot understand the reason.

Below are the codes that can help.

py.

urlpatterns = [
path("", views.PostListView.as_view(), name="list"),
path("slug:slug>/", views.PostDetailView.as_view(), name="detail"),

]

py.models

from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse

class Post(models.Model): 
    title = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, unique=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    body = models.TextField()
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now_add=True)

def __str__(self):
    return self.title

def get_absolute_url(self):
    return reverse("blog:detail", kwargs={"slug": self.slug})

post_detail.html

{% extends "blog/base.html" %}

{% block title %} {{ post.title }} {% endblock %}

{% block content %} 
    <h2>{{ post.title}}</h2>
    <p class="date"> 
        Publicado em {{ post.created}} por {{ post.author}}
    </p>
    {{ post.body|linebreaks}}

{% endblock %}
  • Looks like there was a typo here: path("slug:slug>/",..., because it should be path("slug:<slug>/".... I mean, the <

  • Thank you Paul.. That’s right.!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.