How to except 404 errors correctly?

I have a app with m404 define. And, Django can’t except site errors. Can you help me? Just send here correct exception code.
from django.http import *
from django.http import *
from django.shortcuts import render

    return HttpResponseNotFound("<h2>Not Found</h2>")
def products(request, productid):
    category = request.GET.get("cat", "")
    name = request.GET.get("name", "")
    output = "<h2>Product № {0}  Category: {1}</h2>".format(productid, category)
    return HttpResponse(output)
def users(request):
    id = request.GET.get("id", 1)
    name = request.GET.get("name", "Tom")
    output = "<h2>User</h2><h3>id: {0}  name: {1}</h3>".format(id, name)
    return HttpResponse(output)
def about(request):
    return HttpResponse("<h1>About</h1>")
def contact(request):
    return HttpResponseRedirect("/about")
def index(request):
    header = "Personal Data"
    language = ["Russian", "English", "German"]
    user = {"name": "Tom Bazucki", "category": "Django"}
    addr = ("Апельсиновая", 23, 45)

    data = {"header": header, "language": language, "user": user, "addr": addr}
    return render(request, "index.html", context=data)
def slash(request):
    return HttpResponseRedirect("/index")

from firstapp import views
urlpatterns = [
    path("index/", views.index),
    path('', views.slash),
    path('products/<int:productid>', views.products),
    path('users/', views.users),
    path('about/', views.about)

Just a note for future reference - when you post code here, please enclose it between lines consisting of only three backtick - ` characters. That means you’ll have one line of ```, then your code, then another line of ```. This preserves the formatting of the code making it a lot easier to read - especially with statements where indentation is critical.


# The line above this is ```
def function(self):
    return self
# The line after this is ```

If you can, please edit your post to put the ``` before and after the code for each of the files you’ve posted above.


1 Like

You probably want to review the documentation for Error views and Customizing error views.


1 Like