jack sexton
jack sexton

Reputation: 1287

JsonResponse not setting content-type to application/json using django

Here is the response returned by my view in django. For some reason the web inspector recognizes that the content_type is application/json but when using httpie, it recognizes it as text/html. Am I doing something wrong, which do i trust?

Here is my view code:

def RegistrationView(request):
if request.method == 'GET':
    reg_user = User.objects.create(username=str(User.objects.all().count()+1), password=str(uuid.uuid4()))
    reg_user.save()
    serialized_user = UserSerializer(reg_user)
    json_rend = JSONRenderer()
    import ast
    return JsonResponse(ast.literal_eval(json_rend.render(serialized_user.data)))
return HttpResponse("woah")

Here is the comparison between httpie and the safari web inspector: enter image description here

enter image description here

Upvotes: 0

Views: 727

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599490

In the first screenshot, you are requesting localhost:8000/lkd/. In the second, you are requesting localhost:8000/lkd - note, no trailing slash. In that second case, Django is sending a 301 response which redirects you to the address with the slash, as the rest of that screenshot shows.

Upvotes: 5

Related Questions