1

I'm using a webfaction-hosted django site, and I'm trying to get locally stored images to show properly, but I'm having trouble getting the static directories/permissions/etc. to line up.

I've configured everything according to webfaction's guide at https://docs.webfaction.com/software/django/config.html

In my project's templates folder, I have the line:

<img src="{{ STATIC_URL }}{{ project.overview_image }}">

where project.overview_image is a CharField where I can list a subdirectory where the image is located.

In my settings.py, I have:

STATIC_URL = 'http://morphogen.cc/static/'
STATIC_ROOT = '/home/scottnla/webapps/static_media/'
STATICFILES_DIRS = (
'/home/scottnla/webapps/portfolio_website/portfolio_website/static/'
)

where /webapps/static_media/ is my static media app.

inside of my project's local /static/ folder, i have an image in the folder

/home/scottnla/webapps/portfolio_website/portfolio_website/static/images/small/img.jpg

and when i run 'manage.py collectstatic', the image is copied to:

/home/scottnla/webapps/static_media/images/small/img.jpg

but when I look at my served HTML page, the image doesn't show.

When I inspect the element, I see that the image source is listed as:

<img src="http://morphogen.cc/static/images/small/img.jpg">

which seems consistent with everything above, but if I go directly to that directory, I get a 403 Forbidden Error.

What's the next step in troubleshooting this?

thanks.

nathan lachenmyer
  • 5,298
  • 8
  • 36
  • 57
  • Do you have a static site serving at that directory? – Daniel Roseman Mar 08 '14 at 20:21
  • I've followed the directions on the webfaction documentation, and currently have "/static" is currently being served by "static_media" according to my webfaction account. Is there anything else I should check to make sure that the static site is serving properly? – nathan lachenmyer Mar 08 '14 at 20:25

1 Answers1

0

Your settings.py should look like this.

STATIC_ROOT = '/home/USER_NAME/webapps/static_media/'
STATIC_URL = '/static/'

STATIC_DIR is outdated and unnecessary for a single static folder

ALSO, you must have

INSTALLED_APPS = ( 
     ...
'django.contrib.staticfiles', 
     ...
)

IF you're still having problems check the Django Static Files Documentation

Christopher Reid
  • 4,318
  • 3
  • 35
  • 74