Forums

Static files in Django using virtualenv

Hello,

I know this is a common question but I've followed the tutorial and some of the other forum posts and I'm still stumped :( I'm having trouble serving static files with my Django web app.

I have the following in settings.py:

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")

Under the "web" tab, I've specified the following static file directories:

  • /static/ : home/tsaltas/FuseProject-Prototype/prototype/static/
  • /media/ : home/tsaltas/FuseProject-Prototype/prototype/media/

When I load the app in the browser and inspect the source code, the link URLs appear correct:

  • href="/static/prototype/css/core.css"
  • img src="/media/project_images/winterize1.jpg"

I've fiddled with appending/prepending slashes, hard-coding the STATIC_ROOT and MEDIA_ROOT, etc. and I can't seem to figure it out. I would greatly appreciate any suggestions!

Many thanks in advance,

Shannon

Are you missing the initial slash on /home/?

I just tried it and it worked!! Thank you Harry! I'm sorry to trouble you over something so small.

Thanks so much,

Shannon

You're very welcome. Happy coding!