Forums

How to get static files to actually be served?

Well I added a simple static file test: I updated in the web tab the "Static files:" to have:

Url: /new/ Directory: /home/paul23/heren5_app/assets/Heren5Frontend/index.html

I then hit "reload" on my application.

However if I then browse to mysite, with the query to /new? (so mysite.pythonanywhere.com/new/) there is a 500 error. And the logs give the following:

FileNotFoundError: [Errno 2] No such file or directory: '/home/paul23/heren5_app/new'

Which is weird since the python server shouldn't be even talked to: it's supposed to be a static url.

What goes wrong?

The trailing slash in the URL part of the Static file mapping is specifying that the mapping shouls be treated as a directory, but you're mapping to a single file. If you go to http://paul23.pythonanywhere.com/new/index.html, you'll see that you get the file at /home/paul23/heren5_app/assets/Heren5Frontend/index.html.

Static files works by looking for the file first and if that fails, it passes the request through to your app.