9đź‘Ť
You can use the WSGI container on top of Tornado to host any WSGI application, including Django, however, when you do that the WSGI application is still running as a blocking application and will not magically be running as an asynchronous application. So, when Django is handling a request there is no ability to handle another request at the same time within Django. The solution at that point is not much different to running a single threaded WSGI server and you would need to have multiple Tornado instances to handle concurrent requests.
So all really depends on what you mean by asynchronous. You certainly can’t make use of Tornado’s direct asynchronous programming API in Django. Thus there isn’t really any great benefit from using Tornado with Django via the WSGI interface.
2đź‘Ť
As I understand you are talking about this paragraph in Instagram docs
You should build your system to accept multiple update objects per payload – though often there will be only one included. Also, you should acknowledge the POST within a 2 second timeout–if you need to do more processing of the received information, you can do so in an asynchronous task.
That’s another type of “asynchronous” that Tornado provides.
I think Django + Celery will suite better for this.
Your application will work in this way:
- You receive JSON-data from Instagram
- Create a celery-task, e.g.
instagram_process.delay(request.raw_post_data)
orinstagram_process.delay(request.body)
according to your Django version - Response to Instagram with 200 status code
- In
instagram_process
task you do all your procession – parse JSON, store it do database and anything else you need.
If you want to check X-Hub-Signature
you can either do it between steps 1 and 2, or pass this header to the task and verify the signature at step 4.
- [Django]-Django 2 upgrade lost filter_horizontal functionality
- [Django]-Django 1.5 select_for_update considered fragile design
- [Django]-Django formset if TOTAL_FORMS has different number than actual number of forms
- [Django]-Testing Django project, how can I avoid Errno 10054?
- [Django]-Celery beat process running on Heroku sends task twice
1đź‘Ť
You can use tornado.wsgi to integrate Tornado with other WSGI compliant frameworks. Check out this demo project for details:
- [Django]-Django rest framework custom Response middleware
- [Django]-Framework/Language for new web 2.0 sites (2008 and 2009)
- [Django]-Accessing user home directory from django