2

I am using django rest framework to implement a simple api. Inside my view.py I have this method:

def business_profile_detail(request, pk):
    """
    Retrieve, update or delete a profile.
    """
    try:
        profile = BusinessProfile.objects.get(pk=pk)
    except BusinessProfile.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = BusinessProfileSerializer(profile)
        return JSONResponse(serializer.data)

    elif request.method == 'PUT':
        """
        Method not supported yet
        """
        return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)

    elif request.method == 'DELETE':
        """
        Method not supported yet
        """
        return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)

So for the PUT and DELETE methods, I want to return an error 405, but using the django test server, I keep getting an error 500:

[17/Oct/2014 18:20:22] "DELETE /business/api/profile/2 HTTP/1.1" 500 60487

Anyone knows why?

Thanks!

EDITED:

Traceback:
File "/Users/*******/Documents/dev/offers/project/offers/venv/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/handlers/base.py" in get_response
  137.                 response = response.render()
File "/Users/*******/Documents/dev/offers/project/offers/venv/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/template/response.py" in render
  103.             self.content = self.rendered_content
File "/Users/mariopersonal/Documents/dev/offers/project/offers/venv/lib/python2.7/site-packages/rest_framework/response.py" in rendered_content
  49.         assert renderer, ".accepted_renderer not set on Response"

Exception Type: AssertionError at /business/api/profile/2
Exception Value: .accepted_renderer not set on Response
1
  • 1
    Some traceback there? Commented Oct 17, 2014 at 18:36

1 Answer 1

1

It looks like the Response class you're using there requires a data argument:

Signature: Response(data, status=None, template_name=None, headers=None, content_type=None)

http://www.django-rest-framework.org/api-guide/responses

I'd just use a basic HttpResponse there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.