Gunicorn, Inlets, Whitenoise

Subscribe to my newsletter and never miss my upcoming articles

Ok, tldr; I need to test gunicorn vs manage.py runserver in my local development. Normally gunicorn will not handle the static files serving, since it's nginx or other web server thing. But, in case of inlets, I don't want to setup a web server just to serve the static files, since the manage.py is handling this serving + inlets quite well.

The problem is not really clear, since some javascript and css are loaded from static folder without any problem, but for images it gives 404 status. So, after some trials and errors, I have it resolved by utilising the whitenoise package. What I need is just adding the whitenoise into the middleware part of the setting, like so:

MIDDLEWARE = [
  # ...
  'whitenoise.middleware.WhiteNoiseMiddleware',
  # ...
]

If you go to the documentation site, maybe you need to edit some references to the static folder, but in my case, adding the above line is enough.

Now, gunicorn (or the wsgi) is serving the static files correctly, and using inlets to expose the local port to public is now running perfectly.

Comments (2)

Dallas Spohn's photo

I find gunicorn with supervisor works great with static content both in Nginx or httpd. I mostly write flask or django apps so I realize using them with a static site is moot.

maz solie's photo

Yup, absolutely