Sometimes, a local project may fail to start up. You may see:
This page isn’t working 127.0.0.1 didn’t send any data.
in your web browser, or:
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "postgres" (172.20.0.2) and accepting TCP/IP connections on port 5432?
in the console or logs.
This almost always means that the Django runserver has started up, but wasn't able to connect to the database. Usually, this is because although the web container and the database container were launched at the same time, the database was slower to get started, and when Django tried to connect to it, it found nothing there.
The solution is to restart Django, while leaving the database running.
Try these steps in order:
- stop the web server (
divio project stopor
docker-compose stop, or stop it in the Divio app)
- start the web server in the Divio shell with
docker-compose up(this will allow you to see the console as it runs)
- try loading the site in the web browser - you may get the error about the database connection failure; if so, go on to:
- find the
settings.pyfile in the project
- save it - you don't need to make any changes, the action of saving any Python file in the project will cause the Django runserver to restart
- in the shell, you will see that the runserver has restarted
- if it shows no errors since the restart, try loading the site in the browser once more.