Thursday, January 5, 2017

Django - 009 - A quick note about 404 errors

At this point, our URLconf defines only a single URLpattern: the one that handles requests to the URL /hello/. What happens when you request a different URL? To find out try running the Django development server and visit a page such as: http://127.0.0.1:8000/welcome


You should see a page not found message. Django displays this message because you requested a URL that is not defined in your URLconf.

The utility of this page goes beyond the basic 404 error message. It also tells you precisely which URLconf Django used and every pattern in that URLconf. From that information, you should be able to tell why the requested URL threw a 404.

Naturally, this is sensitive information intended only for you, the web developer. If this were a production site deployed live on the internet, you wouldn't want to expose that information to the public. For that reason, this Page not found page is only displayed if your Django project is in debug mode.

There is a technique to deactivate the debug mode. For now, just be aware that every Django project is in debug mode when you first create it, and if the project is not in debug mode, Django outputs a different 404 response.

No comments:

Post a Comment