The requested URL in my Django app can grow indefinately and still be matched by Django URLResolvers

StackOverflow https://stackoverflow.com/questions/10421408

  •  05-06-2021
  •  | 
  •  

문제

I have the following line in my src/urls.py

(r'^nomundo', include('interviews.urls')),

and in my src/interviews/urls.py I have the following:

r'/$', 'interviews.views.interviews'),

This construction allows me to access URLs such as /nomundo/blablabla/trololo/foo/bar, or any other with as many /something as I want.

I would like these to raise a 404 error.

How can I specify my regexp to do so? Or the solution is something else?

Thank you for your time.

도움이 되었습니까?

해결책

You forgot to root your sub-URL so that it starts at the beginning of the string.

(r'^$', 'interviews.views.interviews')

Note that you usually include the initial slash in the parent's url, which is why I haven't included it above:

(r'^nomundo/', include('interviews.urls')),
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top