I'm confused about passing optional parameter via url in Django with path()
instead of url()
. I found that I should use kwargs
, so I added it to path:
path('all/<str:category>/<int:page_num>/', views.show_all_objects, name="show-all-objects"),
to
path('all/<str:category>/<int:page_num>/', views.show_all_objects, kwargs={'city': None}, name="show-all-objects"),
Ok but now how to pass additional parameter from template, I tried with:
<a href="{% url 'show-all-objects' category='restaurants' page_num=1 city=1 %}"
which returns me common error for NoReverseMatch at /
So I added it to url:
path('all/<str:category>/<int:page_num>/<int:city>/', views.show_all_objects, kwargs={'city': None}, name="show-all-objects"),
But error is the same, I'm pretty sure, that this is not the proper way to do it, but I cannot find info about passing optional parameter via path()
, all info is with url()
Is it possible ?