PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, June 24, 2022

[FIXED] How to serve static files with Waitress and Django?

 June 24, 2022     django, python, reverse-proxy, waitress, web-deployment     No comments   

Issue

I've a tiny web app built on Django that has some static files collected by python manage.py collectstatic. I'm using a lightweight server, Waitress

When I run my server using the script

from waitress import serve

from <my app>.wsgi import application

if __name__ == '__main__':
    serve(application, host = '0.0.0.0', port='8000')

the app loads up to http:localhost:8000 but I notice the static files are not present. From the terminal, I can read

Not Found: /static/<my app>/styles.min.css
WARNING:django.request:Not Found: /static/<my app>/styles.min.css
Not Found: /static/<my app>/buttonhover.css
WARNING:django.request:Not Found: /static/<my app>/buttonhover.css
Not Found: /static/<my app>/script.min.js

Do I need something in addition to Waitress to serve the static files? Do I need a reverse proxy like nginx running alongside Waitress? If so, are there Python reverse proxies available?


Solution

I found a solution using the White Noise library.

Do I need something in addition to Waitress to serve the static files?

Yes. Kinda. You do need something to help Django find the static files, or upload them to a container online like AWS S3.

Do I need a reverse proxy like nginx running alongside Waitress?

No. White Noise is a simple add on to a Django project which in my opinion pairs it well with Waitress since they're self-contained Python projects.



Answered By - Jon
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing