Displaying custom 404 error (page not found) page in Django 2.0

It happens very frequently that a visitor on your website typed a wrong URL or the page user is looking for no longer exists. What do you do to handle such cases?

You have three options.

  • Redirect the visitor to home page, silently.
  • Show a boring 404 error page and then ask them to click on a link to go to home page.
  • Create your own funny/awesome/informative custom 404 error page.

In this article we will discuss the third option i.e. How to show your own error page in Django 2.0 project when a URL is not found.

Code is available on Github.

Featured Image source:  https://www.pinterest.com/pin/101612535313085400/

Continue reading “Displaying custom 404 error (page not found) page in Django 2.0”

Solving Django error ‘NoReverseMatch at’ URL with arguments ‘()’ and keyword arguments ‘{}’ not found.

Every Django developer encounters below error at least once in their life for sure.

Beginners spend many hours debugging the issue, jumping from question to question on Stackoverflow and posting in multiple groups on Facebook.

In this article we have tried to list all the common mistakes developer makes which leads them to above error.

Continue reading “Solving Django error ‘NoReverseMatch at’ URL with arguments ‘()’ and keyword arguments ‘{}’ not found.”

How to start logging errors in Django app

In development or testing environment, you may set DEBUG=True  in your settings.py  file and whenever any error is thrown, you see it in the browser.

Setting DEBUG=True  in production environment is not recommended. Debug should be set to False on live servers so that stack trace is not visible in case of any error. Hackers or malicious users may exploit this and may attack you web application.

So how do you debug you application on live servers? Answer is Logging the errors in log files.

Lets  see how to start logging errors in django?

Continue reading “How to start logging errors in Django app”

Designing custom 404 and 500 error pages in Django

Update 1: Please refer this updated article for Django 2.0 and source code.

 

It happens very frequently that a visitor on your website typed a wrong URL or the page user is looking for no longer exists. What do you do to handle such cases.

You have three options.

  • Redirect the visitor to home page, silently.
  • Show a boring 404 page and then ask them to click on a link.
  • Create your own funny/awesome/informative custom 404 error page.

In this article we will discuss the third option.

Continue reading “Designing custom 404 and 500 error pages in Django”