I've Created a view
urlpatterns = [
path('book/<suffix>/', views.bookview, name='bookDetail')`
]
what i want
- if someone hits url
'127.0.0.1:8000/book/1/2/3/4/5/6/'
- i do not want django to raise an error of
The current path, book/1/2/3/4/5/6/, didn’t match any of these.
- but instead it shows the same view of url
book/<suffix>/
which isview.bookview
. - and somehow pass, suffix after
book/
which is1/2/3/4/5/6/
as arg so that i can access it in my view.
CodePudding user response:
from django.urls import re_path
urlpatterns = [
re_path(r'^book/(?P<suffix>[\w/] )$', views.bookview, name='bookDetail')
]
CodePudding user response:
As there can be special characters in the suffix
parameter, you need to encode the string. In python you can do it like this
from urllib.parse import quote_plus
suffix = quote_plus('/1/2/3/4/5/6/')