Django.urls.resolvers.URLResolver. _reverse_with_prefix() argument after ** must be a Mapping, not set

Asked

Viewed 27 times

0

Hello I’m trying to do an e-commerce with Django, I was following a tutorial until the creation of the products, the page worked ok (no products and categories), when I added a category and a product by http://127.0.0.1:8000/admin/ it returned me this error while trying to enter the product url (http://127.0.0.1:8000/products/).

imagem do erro na pagina

Traceback

My get_absolute_url looks like this:

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

it is present within my models, as follows:

class Product(TimeStampedModel):
    category = models.ForeignKey(Category, related_name="products", on_delete=models.CASCADE)
    name = models.CharField(max_length=255, blank=False)
    price = models.DecimalField(max_digits=12, decimal_places=2, blank=False)
    description = models.TextField(max_length=255, blank=True)
    image = models.ImageField(upload_to="products/%Y/%m/%d", blank=True)
    is_available = models.BooleanField(default=True)
    slug = AutoSlugField(unique=True, always_update=False, populate_from="name")

    objects = models.Manager()
    available = AvailableManager()

    class Meta:
        ordering = ("name",)
    
    def __str__(self):
        return self.name

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

but I see that the error is giving when entering in /products/ and not in /products/product name/

  • Thiago, in his get_absolute_url you’re passing{"slug", self.slug} for Verse, but the method expects to receive a dictionary and you are passing a set. You need to change {"slug", self.slug} for {"slug": self.slug} because they are different data structures.

  • Thank you very much, I hadn’t noticed that. Solved the problem!

No answers

Browser other questions tagged

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