[Answer]-Django throwing error with '/' in url

1👍

I think the error message is misleading here.

Rather than exceeding the amount of parameters I would expect it to not find enough parameters because your .* are greedy,that means that they would try to match as much as possible, so pid would match until the last occuring backslash. I’m not sure why this would work at all.

If your qid and pid parameters cannot contain slashes it would definitely be advised to restrict their corresponding capturegroup to \w+.

Try this pattern:

url(r'^myurl/(?P<pid>\w+)/(?P<qid>\w+)/(?P<trantype>.*)$', views.MyView.as_view(), name='myurl'),

Also you could try to make the capture groups lazy, if \w doesn’t cut it:

url(r'^myurl/(?P<pid>.*?)/(?P<qid>.*?)/(?P<trantype>.*)$', views.MyView.as_view(), name='myurl'),

I use slashes ( Base64 encoded strings ) in my endpoints as well and I have not had issues with them.

Leave a comment