ohhh
ohhh

Reputation: 707

Static files not being served from seperate django staticfile application

I'm using webfaction to make a simple static website. I think I have done everything correctly, but still my static files (i.e css, images) are not being served. I used this guide to set things up:

http://docs.webfaction.com/software/django/getting-started.html

I did everything they told me to, so in brief:

1) made a separate static media application

2) updated settings.py

3) ran

python manage.py collectstatic 

All of the above went pretty much according to plan and I can now see my static files in the staticfile application that I named personalsitestatic. My django application is called personalsite.

The directory structure looks like this:

This is what the relevant values in my settings.py looks like:

STATIC_ROOT = '/home/<myname>/webapps/personalsitestatic/'
STATIC_URL = 'http://<sitename>.com/static/'
TEMPLATE_DIRS = (
"/home/<myname>/webapps/personalsite/PersonalWebsite/templates/",)

I don't have any additional static directories outside of main/static so I am not using STATIC_DIRS. The templates appear to be loading fine, just none of the static files. When I inspect with firefox's debugger/inspect element thing it just says "stylesheet could not be loaded". Can anyone help me out here or at least give me some suggestions for debugging?

Upvotes: 0

Views: 407

Answers (2)

Luigi Polvani
Luigi Polvani

Reputation: 405

I added those two lines to my httpd.conf, after some research this seems to be the safest and best performing way to serve static contents with Apache.

Alias /media/ /home/USERNAME/webapps/APPNAME/media/
Alias /static/ /home/USERNAME/webapps/APPNAME/staticfiles/

Notice i kept the static and media folders outside the "myproject" folder (the one containing py files) since I have a hook in the git repo self deploying the app, so i don't want those files to be in the way.

Upvotes: 0

ohhh
ohhh

Reputation: 707

I was being silly and did not mount it to the /static url, hope this helps someone!

Upvotes: 1

Related Questions