Question

I have a url for product categories

url(r'^(?P<cat>[^/]+/$)', 'reviews.views.category'),

for example, if I am in the url: http://127.0.0.1:8000/ and click on "eletronics" in the menu, I go to http://127.0.0.1:8000/eletronics/ If I click again in other category (e.g. "books"), I go to http://127.0.0.1:8000/eletronics/books/ How I set up my url in way that I just get one (the last clicked) category in the url?

Was it helpful?

Solution

The menu links in your template may be pointing to "electronics/" and "books/" vs "/electronics" and "/books." To conform with DRY, I recommend naming your url patterns and using the {% url %} template tag to load the correct url route.

For example:

url(r'^(?P<cat>[^/]+/$)', 'reviews.views.category', name='category'),

And in your template:

{% url 'category' 'books' %}

Which will return the correct '/books' url route.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top