Question

The problem looks similiar to the problem here: Pythonanywhere, how to use static files? url? ,but I cannot comment there.

I've started learning Django and when everything worked on localhost that on PythonAnywhere it does not.

At projectname/settings.py I've set:

STATIC_ROOT = "/home/*username*/*projectname*/Static/"
STATIC_URL = "/s/"

and even URL's from static folders in apps.

After trying to run

python3 manage.py collectstatic

every file *.js, *.css and images were coppied to the projectname/Static folder.

But... none of them were recognized after launch of the app. I've set

{% load static %}

used tags

{% static "assets/css/theme.css" %}

At the source code I can see the proper link to css file:

<script src="/s/assets/js/seen.min.js"></script>

And everything would be fine, but the "/s/" isn't recognized by django and it tries to find the view in urls.py. After opening the link to: username.pythonanywhere.com/s/assets/js/seen.min.js I've got standard, debug 404 page with the path of urls.py tries.

How to solve this annoying problem?

Était-ce utile?

La solution

You need to add a static file mapping on the web app. Look for the "Static files" heading on the web app tab.

From what I can tell of your setup, you'd need to put "/s/" for the URL and "/home/*username*/*projectname*/Static/" for the directory.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top