Ahmed Wagdi
Ahmed Wagdi

Reputation: 4391

How to add Dynamic URL part that contains a slash

I'm using a dynamic part in the URL in my Django project, as <str:item_code>, some times the str contains a slash / which causes an error not found.

here is how my URL pattern looks like :

    path('find/the/item/<str:item_description>/', views.find_the_item, name="find_the_item"),

is there anyway to force the url to ignore all slashes inside this <str:item_description> part ?

Upvotes: 0

Views: 267

Answers (1)

larsks
larsks

Reputation: 311606

I'm not familiar with Django, but reading the docs it looks as if you might be able to use the path specified instead of str:

path('find/the/item/<path:item_description>/', views.find_the_item, name="find_the_item"),

The path specifier "Matches any non-empty string, including the path separator, '/'. This allows you to match against a complete URL path rather than just a segment of a URL path as with str.".

(from https://docs.djangoproject.com/en/2.2/topics/http/urls/#path-converters)

Upvotes: 6

Related Questions