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
  •  | 
  •  

Pergunta

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.

Foi útil?

Solução

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')),
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top