In PythonAnywhere Web tab:
URL: /static/
Path: /home/username/project/static
In settings.py:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
...
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'project/static'),
)
In template:
{% load staticfiles %}
<link type="text/css" href="{% static 'MyApp/style.css' %}" />
<link type="text/css" href="{% static 'project/style.css' %}" />
...
<script type="text/javascript" src="{% static 'MyApp/script.js' %}" ></script>
I run:
python manage.py collectstatic
which successfuly copies all static files into /home/username/project/static
, however I get 404 errors for all static files. I am only having this error on PythonAnywhere. Everything runs fine on localhost.
The generated html and the 404 errors indicate the files are being searched for at the following locations:
http://username.pythonanywhere.com/static/MyApp/style.css
http://username.pythonanywhere.com/static/project/style.css
http://username.pythonanywhere.com/static/MyApp/script.js
This is what I expected, so I am assuming my misunderstanding lies in where these directories actually lie in PythonAnywhere.
I am very new to Django. See my question: http://stackoverflow.com/questions/30676929/how-do-you-link-to-site-wide-static-files-in-django-1-8" for a more detailed description of my static files structure.
P.S. I am using Django 1.8 in a virtualenv on PA, so please no deprecated/out of date answers.