简体   繁体   中英

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: 在此处输入图片说明

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM