Reputation: 1144
here is my code in urls.py :
def handler500(request, exception):
response = HttpResponseServerError('error.html', {},
context_instance=RequestContext(request))
response.status_code = 500
return response
but i have a :
TypeError: handler500() missing 1 required positional argument: 'exception'
What am i missing ?
edit bis the whole code :
from django.contrib import admin
from django.urls import path
from django.urls import include
from django.conf import settings
from django.conf.urls.static import static
from django.http import HttpResponseServerError
urlpatterns = [path("admin/", admin.site.urls)]
urlpatterns += [path("", include("Exchange.urls"))]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.shortcuts import render_to_response
from django.template import RequestContext
def handler404(request, exception, template_name='404.html'):
response = render_to_response('404.html', {},
context_instance=RequestContext(request))
response.status_code = 404
return response
def handler500(request,exception):
response = HttpResponseServerError('error.html', {},
context_instance=RequestContext(request))
response.status_code = 500
return response
so here is the whole urls.py file, it seems that my post is mostly code so i have to add more details like the fact this is the django 2.0 version or it runs on python3.6 on a ubuntu os.
Upvotes: 0
Views: 5216
Reputation: 16485
If you take a look at the docs, there it defines the 500 handler with just one positional argument.
Change you code from
def handler500(request, exception):
to
def handler500(request):
Let us know if that works.
Just a hint: django docs on customizing error views suggests placing your view functions in views.py
and just adding the string name to your urls.py
, like:
# in views.py
def handler500(request):
...
# in urls.py
handler500 = 'mysite.views.handler500'
Upvotes: 6