2👍
def photoalbum_GET(request, album_id):
o = get_object_or_404_alt(PhotoAlbum, id=album_id)
if isinstance(o, HttpResponse):
return o
return response_message('', 200)
HttpResponse
is not method, but class. And it is not exception to be raised.
0👍
Additionally to @f43d65 ‘s answer, HttpResponse has to be:
if object.is_deleted:
return HttpResponse('Object was deleted', status_code=404)
if object.is_active == False:
return HttpResponse('Object is not active', status_code=403)
Reference: Django documentation: Request and response: HttpResponse
- [Answered ]-Not able to set custom 404 page (Django 1.9)
- [Answered ]-How to route DetailView to inherit user and slug
- [Answered ]-Segmentation fault when run django celery
Source:stackexchange.com