X
X
Xaip2018-06-16 20:49:43
Tornado
Xaip, 2018-06-16 20:49:43

What is the correct way to pass an HttpRequest to Tornado so that Django will correctly accept the QueryDict?

You need to correctly send an asynchronous POST request to django so that it correctly receives the data. So far, it gives me a QueryDict object:
Part of the code in tornado

http_client = httpclient.AsyncHTTPClient()
        url = "http://127.0.0.1:8000/api/v0/thread/add/"
        headers = {'Authorization': 'JWT ' + self.token}
        context = {'thread':self.thread, 'message':self.message}
        body = json.dumps(context)
        print(body)
        request = http_client.fetch(request=url, method="POST", headers=headers, body=context)

In django I try to catch a request via request.data or request.post but I get:
<QueryDict: {'{"thread": 1, "message": "09up9"}': ['']}>

And you need:
{"thread": 1, "message": "09up9"}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-06-16
@Xaip

From Tornado, the request was sent correctly. It's just that Django accepts the request body this way. With QueryDict, you can perform all the same operations that you perform with a regular dictionary. Optionally, you can cast it to a regular dictionary -d = query_dict.dict()

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question