HttpResponse not returning anything in POST

时间:2016-04-04 17:23:49

标签: python json django

I'm new to Django so please excuse me if this is a silly question. I'm trying to create a very simple REST API where a file gets sent via POST and Django returns a json string.

Here is my code in views.py:

def evaluate(request):
    return HttpResponse(json.dumps({"hello world": 123}))

And in urls.py:

urlpatterns = [
    url(r'^evaluate/$', csrf_exempt(views.evaluate), name='evaluate'),
]

When I do a GET request to /evaluate/ I get back {"hello world": 123}, however I receive a blank response when I send the exact same request as a POST.

Any ideas how I can have POST requests return the JSON as well?

1 个答案:

答案 0 :(得分:0)

我做了一些进一步的调查,发现Chrome上的CORS导致了这个问题。这是解决方案的链接:https://stackoverflow.com/a/30956822/563762