So, I'm using Django and pythonanywhere in order to setup an webpage, but I'm facing some issues when retrieving static files.
I've followed the tutorial for static files (which is great btw) and everything works for the index.html page. However, when trying to go to a second page, it throws an error which fits one of the issues described in this other link: https://help.pythonanywhere.com/pages/DebuggingStaticFiles/
The path to the file and the path in the URL don't quite match (eg, there's an extra level of folder hierarchy in one and not the other)
However, I don't know how to fix it... What is happening is that my log info shows that I'm loading:
/static/pgbfiles/medicine.png -- this is working for the index.html
/publicacoes/static/pgbfiles/img.css -- for the second page named publicacoes.html
What I would like to have is all the static files in one single folder. They are already there but I don't know how to tell Django that they are all there for both html files...
I think I could add an additional folder for the "publicacoes" files, but that is not what I would like to do atm.
And this is how I'm loading the info on both index and publicacoes.html:
{% load static %}
And then on the particular places where I need: href="{% static 'pgbfiles/bootstrap.min.css' %}"
Thank you for any help!
EDIT:
index.html is using: {% static 'pgbfiles/bootstrap.min.css' %} and working;
publicacoes.html was using {% static 'pgbfiles/img.css' %} but I changed it to {% static '/pgbfiles/img.css' %} and it is still not working -> still requests for "GET /publicacoes/static/pgbfiles/img.css".
Static info are: STATIC_URL = 'static' STATIC_ROOT = '/home/guideo/pgbadvogados/blog/static'
WORKING:
Now I've changed STATIC_URL to '/static' and it worked! So thanks a lot for the two comments and answer down below.
(only had to change it on settings.py, and not on publicacoes.html as I was doing before).
You're specifying a relative path (no preceding forward slash), so the request is going relative to the location of the page that contains it. Add a preceding slash to your href.