Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Django to Heroku using a Windows machine (Production server NOT development server)

I use a Windows machine and have a Django project that I have successfully deployed to Heroku, albeit using the development server. To use a production server Heroku seems to require 'Gunicorn' which does not run on Windows.

This is not good for testing locally before deploying. Does anyone know of any way to get around this? Perhaps some way to use a different server on Heroku?

like image 383
Kalail Avatar asked Mar 25 '12 12:03

Kalail


People also ask

What server does Django use for development?

Gunicorn is the recommended HTTP server for use with Django on Heroku (as referenced in the Procfile above). It is a pure-Python HTTP server for WSGI applications that can run multiple Python concurrent processes within a single dyno (see Deploying Python applications with Gunicorn for more information).

Does Django need a Web server?

Django, being a web framework, needs a web server in order to operate. And since most web servers don't natively speak Python, we need an interface to make that communication happen. Django currently supports two interfaces: WSGI and ASGI.


2 Answers

I found a solution that may help when deploying to heroku using a Windows machine. Here is what I do:

Use the development server locally with:

python manage.py runserver

Install and add 'Gunicorn' to your installed apps in settings.py.

Add a process file in the root directory that tells heroku to use the Gunicorn server. This is a file called 'Procfile' with the following code:

web: python kalail/manage.py run_gunicorn --bind=0.0.0.0:$PORT

This way you test using the development server, while heroku uses the Gunicorn server. Make sure you set up serving static files(css/js/imgs) after this, because only the development server automatically serves static files, and the Gunicorn server will need to be configured to do so.

like image 134
Kalail Avatar answered Sep 24 '22 10:09

Kalail


You can run the development server locally quite easily:

> python manage.py runserver
like image 40
Kenneth Reitz Avatar answered Sep 20 '22 10:09

Kenneth Reitz