Forums

Django: Empty argument in url returns error

Hi

I have this url in Pythonanywhere: http://karanasoskostas.pythonanywhere.com/damage/damage/list_dates/20_09_2018/20_09_2018///

which return error Page not found (404) Using the URLconf defined in deya.urls, Django tried these URL patterns, in this order:

^$ [name='frontpage']
^admin/
^damage/ ^test/$ [name='test']
^damage/ ^testpdf/$ [name='testpdf']
^damage/ ^guest/$ [name='index']
^damage/ ^damagetype_add/$ [name='damagetype_add']
^damage/ ^hometest/$ [name='hometest']
^damage/ ^map/$ [name='map']
^damage/ damagetype/add/$ [name='damagetype-add']
^damage/ damage/add/$ [name='damage-add']
^damage/ damage/list_dates/(?P<pfromdate>[-\w]+)/(?P<ptodate>[-\w]+)/(?P<pdamagestatus>.*)/(?P<pdamagetype>.*)/$ [name='damage-list-dates']
^damage/ damage/list/(?P<pk>[0-9]+)/$ [name='damage-by-id']
^damage/ damage/list/criteria/$ [name='damage-list-criteria']
^damage/ damage/markers/(?P<pfromdate>[-\w]+)/(?P<ptodate>[-\w]+)/(?P<pdamagestatus>.*)/(?P<pdamagetype>.*)/$ [name='damage-list-markers']
^damage/ damage/contact/(?P<pfromdate>[-\w]+)/(?P<ptodate>[-\w]+)/$ [name='contact-list-dates']
^damage/ contact/list/criteria/$ [name='contact-list-criteria']
^frontpage/ [name='frontpage']
^contact/ [name='contact']
^deyausers/$ [name='index-deya']
accounts/

The current path, damage/damage/list_dates/20_09_2018/20_09_2018/, didn't match any of these.

But locally this url : http://127.0.0.1:8000/damage/damage/list_dates/20_09_2018/20_09_2018///

works fine.

Can someone help me , find why this is happen ?

Thanks in advanced

Kostas

Interesting. It looks like the trailing /// is being converted down to just /, which is causing the problem -- for example, if you go to http://karanasoskostas.pythonanywhere.com/damage/damage/list_dates/20_09_2018/20_09_2018/5/3/ then the URL will match (though it will give an error because nothing is matching a query you're doing).

From googling around, I get the impression that multiple consecutive slashes in a URL is not strictly valid according to the HTTP spec (though it's not 100% clear that that is the case). For example, this Stack Overflow post reports that Apache converts multiple slashes to a single one. We use nginx rather than Apache, but it seems likely that it does the same.

Perhaps you could use something other than an empty path element to represent "no damage status" and "no damage type", for example http://karanasoskostas.pythonanywhere.com/damage/damage/list_dates/20_09_2018/20_09_2018/None/None/?

Thanks a lot for your answer. I will try the /None/None/? version

Kostas

OK -- would love to hear if that helps!

This worked fine

Thanks a lot

Kostas

Great! Thanks for confirming.

Oh, just for clarity -- the trailing ? in my post was part of the question, not part of the URL. The URL I was suggesting was:

http://karanasoskostas.pythonanywhere.com/damage/damage/list_dates/20_09_2018/20_09_2018/None/None/