Categories
Python Answers

How to make Python Django serve static files with Gunicorn?

Spread the love

Sometimes, we want to make Python Django serve static files with Gunicorn.

In this article, we’ll look at how to make Python Django serve static files with Gunicorn.

How to make Python Django serve static files with Gunicorn?

To make Python Django serve static files with Gunicorn, we append the static file routes to urlpatterns.

For instance, we write

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

# ... 

urlpatterns += staticfiles_urlpatterns()

to append the route list returned from staticfiles_urlpatterns to urlpatterns.

Conclusion

To make Python Django serve static files with Gunicorn, we append the static file routes to urlpatterns.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *