django-ninja
django-ninja copied to clipboard
Handling errors
I´m trying to use custom templates for errors. I followed the handling errors docs but it doesnt work. Do I need to implement something more? I´m using Jinja2 for the template system.
front = NinjaAPI(urls_namespace='front')
env = environment(loader=PackageLoader("front"), autoescape=select_autoescape())
@front.exception_handler(django.http.Http404)
def validation_errors(request, exc):
template = env.get_template("404.html")
data = {
"request": request,
}
return HttpResponse(template.render(data))
@front.exception_handler(ninja.errors.HttpError)
def validation_errors(request, exc):
template = env.get_template("500.html")
data = {
"request": request,
}
return HttpResponse(template.render(data))`
Hi @chrisbodon could you define "does not work" ? does it give some error / what do you see ?
It shows the default message "A server error occurred. Please contact the administrator."
@chrisbodon are you running with ./manage.py runserver
? Do you have DEUBG=True
in settings ?
I am running with ./manage.py runserver --insecure, and this is my DEBUG code at the moment:
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
@chrisbodon set DEBUG = True
and you should see more useful information ;)
I did, but than I get the 404 standard Django page, and not my custom version