문제

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 doesn'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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top