-2

My url is like this below. it accepts /tracks/1 ,/tracks/2

path('tracks/<int:pk>',views.tracks,name='tracks'),

However I want to accept /tracks without pk value.

How can I do this?

whitebear
  • 11,200
  • 24
  • 114
  • 237
  • 1
    Does this answer your question? [Django optional url parameters](https://stackoverflow.com/questions/14351048/django-optional-url-parameters) – Yevhen Kuzmovych Aug 16 '22 at 10:47

1 Answers1

1

Just add another route to the urlpatterns that returns the same view (or any view you want)

path('tracks/<int:pk>',views.tracks,name='tracks'),
path('tracks/',views.your_view ,name='name'),
JSRB
  • 2,492
  • 1
  • 17
  • 48