Routing to a Service-Worker with Flask and PythonAnywhere

If you get a 404 error when you try to access https://xxxxx.pythonanywhere.com/sw.js from the browser, then it’s not your Flask route — it’s your static route. If you have a static file mapping with the “URL” set to /static then it will only pick up requests starting with https://xxxxx.pythonanywhere.com/static.

If you want to set up a static route specifically for the file sw.js and you want it to be accessible from https://xxxxx.pythonanywhere.com/sw.js, then you need to set up a static file mapping with a “URL” of /sw.js, and the “Directory” set to the full path to the file, for example /home/xxxxx/mysite/static/sw.js.

Check out the PythonAnywhere documentation for static files for more details.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top