Frage

In urls.py urlpatterns I have such declaration:

url(r'^product-(\d+)-([a-zA-Z_]+)$', 'product', name="product"),

Second group in regexp is SEO name not needed in view.

In view I have:

def product(request, product_id, suffix):

but suffix is neither required nor used by me. It's there only for SEO.

Is there any way to get rid of this parameter?

War es hilfreich?

Lösung

Remove the parenthesis around the SEO name:

url(r'^product-(\d+)-[a-zA-Z_]+$', 'product', name="product"),

Now the pattern will not be captured and passed on to your view.

If grouping is required, use a non-capturing group ((?:...) instead of (...)):

url(r'^product-(\d+)-(?:[a-zA-Z_]+)$', 'product', name="product"),
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top