Django static files are causing 404 error

Hi, I’m using django on Koyeb. Static files are causing 404 error (even though they exist).
In local computer I run “python collectstatic” command to get rid of 404 issue. I couldn’t figure out how to do this on Koyeb servers. Could you please help?

Hi @rasitozdas. Application servers for Django typiclly don’t handle static files when running in production by default. Instead, the usual route is either to deploy behind a conventional web server like Apache or Nginx that will serve any static content or to configure Django to upload all files to an external object storage bucket like S3.

The basic idea is covered in this Django doc on deploying static files. Running python collect static could be a component of that workflow that you could run by setting the build command while deploying (it will run after the normal build commands). You typically would still need additional steps though to serve the collected static files, as the Django documenation describes.

As an alternative, you can check out our Django deploy doc that uses a plugin called WhiteNoise to store and serve these files. This makes it pretty straightforward to get the desired result without using additional services.

Hope that helps!