Question

I'm trying to get a fresh installation of Django 1.5 running on an Apache-Server. The WebServer is situated on a shared hosting platform called uberspace.de which means I have no access to the Apache configuration itself I can however write .htaccess files if that's any help at all. Django is deployed via fast-cgi which is working as expected.

Whats not working however is the access to static files on the server like the .css files and graphics for the Django administration interface. As mentioned in the official docs I used the following command to copy the static Files into my ~/html/static directory.

manage.py collectstatic

And these are the values from my settings.py:

STATIC_ROOT = '/home/bier/html/static/'
STATIC_URL = '/static/'

All I get is the infamous django 404 page when I try to access any of these Files. I also followed the 'How to install and deploy Django' guide on my Webhosters Website to the letter. (sorry its only available in german I believe) I already contacted the webhosters support but they don't know whats wrong.

All the solutions I've come up with so far suggest setting some sort of Alias in the Apache configuration. Which I can not do.

I'm thankful for any ideas you might have.

Was it helpful?

Solution

Try using a full address instead.

STATIC_ROOT = '/home/bier/html/static/'
STATIC_URL = 'http://www.mysite.com/static/'

Edit: Perhaps you could ask your host to setup /static/ in your Apache config:

sudo nano /etc/apache2/sites-enabled/mysite.com and add:

Alias /static/ /home/bier/html/static/

I've had a situation before where I've had to upload /static/ files manually because of a highly restrictive host (permissions). Perhaps you need to download a copy of django to your desktop and then upload the static admin file set into your /static/ directory manually?

Lastly, have you added the static files to your urls?

url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root': '/home/bier/html/static'}),

OTHER TIPS

I have more simpler solution. you need to create a directory named, let's say 'x' in "public_html" or similar location from which server serves the files by default.

Then upload all static files in directory x. (this can be done by running collectstatic locally and then upload all contents of directory STATIC_ROOT to x)

Then, change your STATIC_URL and STATIC_ROOT as follows:

STATIC_URL = '/x/'
STATIC_ROOT = os.path.join(BASE_DIR, '../public_html/x') # Path to folder
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top