WebFaction
Community site: login faq
0
1

I am trying to serve static media (such as JS and CSS files, not user uploaded content) on a Webfaction-hosted Django setup. I tried to implement what was suggested in the second answer here (http://community.webfaction.com/questions/1148/serving-django-static-media-from-within-the-application) but I can't seem to get it working.

My current set-up is as follows. The static media is stored in django/PROJECT/static. A symbolic static-only app called "static" is linked to django/PROJECT/static as well. The static app is added to the website under the directory /static. Static files in Django are accessed like "{{ STATIC_URL }}example.css".

settings.py:

STATIC_ROOT = 'home/USERNAME/webapps/django/PROJECT/static/'
STATIC_URL = 'http://USERNAME.webfactional.com/static/'
STATICFILES_DIRS = ( 'home/USERNAME/webapps/django/PROJECT/static/', )

Suffice to say, I can't get any of my static files to load. If I browse to USERNAME.webfactional.com/static/example.css I get a 404 Not Found.

How can I get static media working? Thanks for any help you can provide.

(One note: I am also planning on using user-uploaded content, hence why I am using STATIC_ instead of MEDIA_).

asked 22 Aug '11, 23:07

albeit
3113
accept rate: 0%

edited 22 Aug '11, 23:09


Just to confirm - are you certain that the path:

/home/USERNAME/webapps/django/PROJECT/static/example.css

exists on your server? Also, your STATIC_ROOT and STATICFILES_DIRS should be:

STATIC_ROOT = '/home/USERNAME/webapps/django/PROJECT/static/'
STATICFILES_DIRS = ( '/home/USERNAME/webapps/django/PROJECT/static/', )

as the leading slashes are necessary to designate a path as absolute, rather than relative.

Hope that helps!

permanent link

answered 22 Aug '11, 23:27

ryans ♦♦
5.0k93460
accept rate: 43%

edited 22 Aug '11, 23:30

Doh. I recently changed my static media directory from "media" to "static" locally, commited in git and pushed up the server, but didn't realized I needed to re-add "static" before I commited... learning Git as well. Thanks for the help! The leading slashes were there I just forgot them when I typed this. But yep, the PROJECT/static directory didn't even exist, so that was the problem. Thanks again.

(22 Aug '11, 23:42) albeit

I get an error when running collectstatic if I have the same line in STATIC_ROOT and STATICFILES_DIR.

ImproperlyConfigured: The STATICFILES_DIR setting should not contain the STATIC_ROOT setting.

permanent link

answered 26 Jul '13, 16:58

payetti
1
accept rate: 0%

@payetti : I believe that the above accepted answer to this question above is incorrect (although it may have been correct when it was originally posted in 2011.

STATIC_ROOT is the location to which the files in your various STATICFILES_DIRS directories are collected, so you shouldn't need to have the same location in both of them. STATIC_ROOT should be the directory of your static application, and STATICFILES_DIRS should contain directories that contain static assets that aren't tied to a particular Django app.

(26 Jul '13, 17:05) seanf

That makes sense. Things are finally up an running. Thanks Sean.

(26 Jul '13, 20:27) payetti
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×125
×22
×17

question asked: 22 Aug '11, 23:07

question was seen: 10,617 times

last updated: 26 Jul '13, 20:27

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM