[Answered ]-How to call HttpResponse from external function?

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.

👤f43d65

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

👤Wtower

Leave a comment