handler500

55 views
Skip to first unread message

Marc Streeter

unread,
Nov 23, 2020, 12:18:56 PM11/23/20
to Django REST framework
Using: 
 - django 3.1.3
 - djangorestframework  3.12.2

I've been trying to get `handler500` to work with `@api_view` decorator.

## Steps to reproduce

provide the view like so

populate file core/util/response.py

```
from rest_framework.decorators import api_view
from rest_framework.response import Response 

@api_view(["GET"])
def handler500(request):
    payload = {"message": "system error", "success": False, "data": None }
    return Response(data=payload, status=500, exception=True)
```
populate file app/urls.py
```
handler500 = "core.util.response.handler500"
```

and then starting Django with 

```
python manage.py runserver 0.0.0.0:8888
```

## Expected behavior

starts Django successfully (with handler500 able to be used)

## Actual behavior

Django crashes on start up with the following error

```
ERRORS:
?: (urls.E007) The custom handler500 view 'core.util.response.WrappedAPIView' does not take the correct number of arguments (request).

System check identified 1 issue (0 Silenced).
```



## Additional notes:
I am able to use the above with `handler404` without issue (and it works as expected), for `handler500` I have to use `django.http.HttpResponse` instead.

Chetan Ganji

unread,
Nov 30, 2020, 2:16:05 AM11/30/20
to django-res...@googlegroups.com
Hey,
Could you try with below code?

def handler500(request, *args, **kwargs):

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/1a3c89fa-df02-41e9-a7f3-39fc7227516an%40googlegroups.com.

Chetan Ganji

unread,
Nov 30, 2020, 2:19:02 AM11/30/20
to django-res...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages