[BUG] 404 handler override not working as expected
Describe the bug
I have a simple demo Django-Ninja app working thanks to a helpful onboarding documentation on the related docs.
All of the endpoints in my simple demo work as expected.
However, the following code in my urls.py file does not produce the expected result based on the docs:
from django.http import Http404@api.exception_handler(Http404)
def page_not_found(request, exc):
return api.create_response(
request,
{"message": "Please retry later"},
status=404,
) I expect my handler to pick up 404s when the server is running, but I get the default
Not Found The requested resource was not found on this server.
Did a lot of research beforehand and tried a variety of overrides, but none worked-- so am documenting the method from the dn docs: https://django-ninja.dev/guides/errors/
My code is here: https://github.com/ErikPohl444/django_ninja_playground
Working control case: http://127.0.0.1:8000/api/hello_html?name=you
Not working experimental case: http://127.0.0.1:8000/api/this_endpoint_is_undefined
I've done similar captures of the 404 in Flask and in Django, but I'm hitting a wall here.
It is either: a) something is buggy with d-n [unlikely] b) something can be added to for newbies like me to the documentation [potentially] c) my code is buggy [in which case I might want to make a PR with doc changes --see b -- for folks like me :) ]
Versions (please complete the following information):
Python version: [e.g. 3.6] Python 3.12.0
Django version: [e.g. 4.0] Django==5.1.4
Django-Ninja version: [e.g. 0.16.2] django-ninja==1.3.0
Pydantic version: [e.g. 1.9.0] pydantic==2.10.4
Source: vitalik/django-ninja