We're running our development environment in a virtualbox Ubuntu LTS 12.04 guest, in Windows 7 host. We use ./manage.py runserver during development.
Recently we upgraded our Django version to latest (1.4.19) but noticed a very odd behaviour: requests coming from host machine take anything from 5-30s to serve, while requests from inside VM are served in less than a second, as they should be. The problem has been introduced in Django 1.4.18 (https://docs.djangoproject.com/fr/1.7/releases/1.4.18/), all older releases work fast.
Using different browser in guest or host makes no difference. It also does not make any difference whether the requested resource is dynamic or static (we use the static app to serve static content during development).
What could cause this kind of behaviour? From the release notes it's not immediately clear to us.
Wow I can't believe I finally managed to solve this. I had exactly the same issue and you put me on the right track by mentioning that it only appeared for version later than Django 1.4.17.
Short solution: add your gateway IPs to /etc/hosts in your guest machine, e.g:
Long explanation: Django 1.4.18 introduced the stripping of headers that contain underscores. That's harmless, but the
django.core.servers.basehttp.WSGIRequestHandler.get_environ
method was slightly altered. From 1.4.18 on, it relies onwsgiref.simple_server.WSGIRequestHandler.get_environ
, which contains the line:address_string
is a method fromBaseHTTPServer
:That call to getfqdn is the (slow) culprit:
After I added the "10.0.2.2 10.0.2.2" line to
/etc/hosts
in my guest machine, hostname resolution was near instant:Note that your gateway address can be found by running
route -n
in your guest environment.