M
M
MalekBV2021-07-26 20:46:39
Django
MalekBV, 2021-07-26 20:46:39

Regex url django. How to make multiple slugs clean url?

I need url by type

/catalog/catalog_slug/tag_slug1/tag_slug2/tag_slug3
to filter catalog items by tags

re_path(r'^catalog/(?P<catalog_slug>\w+)/(?P<tag_slugs>(?:\w+/)+)', ...)


I read how to make multiple tag_slugs ( here ), but when I mix it with another model's slug (catalog) I get:
TypeError: get() got multiple values for argument 'catalog_slug'


view
class CategorySeoTagsView(APIView):
    def get(self, catalog_slug, tag_slugs):
        pass

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
K A, 2021-07-27
@russrage

See get_absolute_url in the model and subdirectories.

class Category
...
def get_absolute_url(self):
        return reverse(
            'catalog:product_list_by_category',
            kwargs={'category_slug': self.slug}
        )


class Product
...
def get_absolute_url(self):
        return reverse(
            'catalog:product_detail',
            kwargs={
                'product_slug': self.slug,
                'category_slug': self.category.slug
            }
        )

Something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question