Hi,
From my Django application's template, I need to post some data to the
same Django application's view, and there is a method in view that should
perform further operations with them. From my JavaScript, I am trying to
send a bunch of requests at the same time, like this:
$.when(function01(),
function02(),
function03(),
function04()
).done(function() {
/** some debug messages and whatnot **/
});
Each of those functions has an Ajax call and entry trace messages. In my
Django views.py, I am tracing my method also. From the messages in the web
console, it is apparent that those functions were all called at (almost)
the same time. But from the traces in the Django view method, the Ajax
requests were served sequentially, one at a time.
Here is what my Django view method looks like:
# I import the python Requests library here@ensure_csrf_cookiedef
CrossDomainProxy(request):
try:
cross_domain_url = <some_already_known_url>
headers = {'content-type': 'application/json', 'Authorization':
request.META['HTTP_AUTHORIZATION']}
cross_domain_response = None
if request.POST:
payload = dict(request.POST.iterlists())
cross_domain_response = requests.post(cross_domain_url,
headers=headers, data=payload)
else:
cross_domain_response = requests.get(cross_domain_url,
headers=headers)
response = HttpResponse(cross_domain_response,
mimetype="application/json", status=cross_domain_response.status_code)
except:
reponse = HttpResponseBadRequest('<h1>bad request!</h1>')
return response
The idea here is to bypass the same origin policy of Ajax, and it works,
but the requests are handled sequentially. I believe the python
Requests<http://docs.python-requests.org/en/latest/>module is a blocking
one-task-at-a-time kind of library, which could be the
reason this is happening. But if I use a library like
Treq<https://github.com/dreid/treq>,
I cannot return an HTTP response object, which is mandated by Django.
I have already tried different browsers and raising the number of TCP
connections allowed per server, and that is not the culprit here.
I am running Django application using uWSGI from the project root like this:
uwsgi --async 30 --ugreen --uid www-data --http :8000 --enable-threads
--wsgi-fi wsgi.py --static-map /static=./static --static-map
/templates=./templates --processes 10
Needless to mention, I have tried running it as the usual development
server also, and if this does not do it, neither will that.
How can I get the Django view methods to handle requests coming from the
same source parallelly?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/dd31c8a8-218f-4e33-b261-91a54223bc81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.