Forums

Currently unable to load static image

  1. Followed the instructions at https://help.pythonanywhere.com/pages/DjangoStaticFiles/,

  2. STATIC_ROOT = "/home/mbak000/hioa_site/static",

  3. on web tab, URL: /static/ AND directory: /home/mbak000/hioa_site,

  4. In template, {% load static %} AND <img src = "{% static '/logoflame.jpg' %}">,

  5. ran python manage.py collectstatic - got this error: ImproperlyConfigured: You're using the staticfiles app without having set the required STATIC_URL setting,

  6. tried to load web page and got this 500 error: Not Found: /static/logoflame.jpg

From that error message, it sounds like you have removed the STATIC_URL setting that Django provides by default in your settings.py. Do you have anything in your settings to define that variable?

Thank you. I added back to settings.py: STATIC_URL = 'static/', ran python manage.py collectstatic, and reloaded on the Web tab. I am still getting this error: Not Found: /logoflame.jpg

I see there's some discrepancy between p. 2 and 3 of your initial post -- could you try changing static file mapping for /static/ to /home/mbak000/hioa_site/static, reload the web app and see if that helps?

Thank you. I changed the settings.py to have: STATIC_URL = '/home/mbak000/hioa_site/static' (and kept STATIC_ROOT = "/home/mbak000/hioa_site/static"). I reloaded the web app and I still get Not Found: static/logoflame.jpg. If I try to run python manage.py collectstatic, I still get: ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. Can someone please tell me what to put in settings.py? (in my template, I have {% load static %} AND <img src = "{% static '/logoflame.jpg' %}">). I don't understand why this is so tricky.

The Django docs will explain it better than anyone can here - https://docs.djangoproject.com/en/5.1/howto/static-files/

Thank you. I did the Django doc and couldn't get it to work, then I tried the Python Anywhere instructions. There must be something obvious that I am missing. If someone can please look at my settings, they would probably see any inconsistency. This is typically just two or three steps like in the Django doc and Python Anywhere instructions.

Looking at your static site configuration, I'm seeing a mapping from /static/ to /home/mbak000/hioa_site. It should go to /home/mbak000/hioa_site/static to match the STATIC_ROOT. Once you've fixed that, you need to use the "Reload" button at the top of the "Web" page to activate the change.

That worked! Thanks so much, giles!

Glad to hear that!