Optional get parameters in django?

后端 未结 7 1671
后悔当初
后悔当初 2020-12-05 00:28

Can someone please explain how you can write a url pattern and view that allows optional parameters? I\'ve done this successfully, but I always break the url template tag.

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 01:14

    Why not have two patterns:

    (r'^so/(?P\d+)/(?P.*)/$', view='myapp.so', name='optional'),
    (r'^so/(?P\d+)/$', view='myapp.so', kwargs={'optional':None}, name='required'),
    

提交回复
热议问题