开发者

python urlpattern newbie question [closed]

开发者 https://www.devze.com 2022-12-22 15:30 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I'm trying this pattern:

(r'^jobs/(?P<job_id>\d+)/$', job_handler)

To work with jobs/ and jobs/{job_id}, but the above expression doe开发者_如何学JAVAsn't cover the first case(jobs/), it only work if I do something like:

(r'^jobs/$', job_handler),
(r'^jobs/(?P<job_id>\d+)/$', job_handler) 


You need to make the second part optional:

(r'^jobs/(?:(?P<job_id>\d+)/)?$', job_handler)
0

精彩评论

暂无评论...
验证码 换一张
取 消