WebFaction
Community site: login faq

I'm pretty shaky when it comes to Django deployment and I've had trouble grasping Web Faction's various 'static' applications and how they intertwine with Django. I have a Django project with an 'apps' directory containing all the apps and alongside that I have a 'media' directory, which holds all my static content, including CSS, JS, as well as files uploaded via the admin. How do I properly configure my Web Faction applications to accommodate this setup?

Here's what I've got now...

I have a 'jolby_dev' Django 1.2.3 app set up in Web Faction, as well as a 'jolby_dev_static' 'Static only (no .htaccess)' app. Under ~/webapps/jolby_dev_static/ I have a symlink of 'media' pointing to ~/webapps/jolby_dev/jolby/media/. Then in my Django settings.py, I have:

MEDIA_ROOT = '/path/to/home/webapps/jolby_dev/jolby/media/'
MEDIA_URL = 'http://www.my-dev-url.com/media/'

Finally, for admin media, I have a 'jolby_dev_static_admin' 'Symbolic link to static-only app', pointing to ~/webapps/jolby_dev/lib/python2.6/django/contrib/admin/media, and this in my settings.py for that:

ADMIN_MEDIA_PREFIX = 'http://www.my-dev-url.com/media/admin/'

The problem I'm getting is 404s anytime I try to access a file upload through the admin. The URL looks correct but the file doesn't serve. Anyone know what I'm doing wrong?

asked 20 Dec '10, 16:55

chrisforrette
122
accept rate: 0%


You have:

Under ~/webapps/jolby_dev_static/ I have a symlink of 'media' pointing to ~/webapps/jolby_dev/jolby/media/.~/webapps/jolby_dev/jolby/media/.

The symbolic link should be in your ~/webapps/jolby_dev/jolby directory. It should be named media and it should point to ~/webapps/jolby_dev_static/media

MEDIA_ROOT = '/path/to/home/webapps/jolby_dev/jolby/media/'

This should be:

MEDIA_ROOT = '/home/username/webapps/jolby_dev/jolby/media/'

Replace username with your username

Everything else looks correct. If you would like for us to look at your actual configuration on the server, please open a support ticket.

permanent link

answered 20 Dec '10, 17:06

aaronh ♦♦
1.3k3
accept rate: 34%

Thanks for the response! So under ~/webapps/jolby_dev/jolby/media/ I have js/, css/, images/, etc. -- what you're suggesting would require me to move all of these under ~/webapps/jolby_dev_static/, delete the 'media' directory in my app and make a symlink in it's place. Is there any way to do it so that I don't need to move any of this stuff from where it is now?

(20 Dec '10, 23:13) chrisforrette

Your interpretation is correct.

I will add another solution that does not require moving your files. Both arrangements are possible.

(20 Dec '10, 23:30) ryans ♦♦

You have:

Under ~/webapps/jolby_dev_static/ I have a symlink of 'media' pointing to ~/webapps/jolby_dev/jolby/media/.~/webapps/jolby_dev/jolby/media/.

The problem is that you have a "Static-Only (no .htaccess)" application named jolby_dev_static. This is designed to put static files directly inside. It's not really designed to contain a symlink pointing to static files, because then the symlink name must be present in the URL. This makes for either ugly URLs or 404 errors when the "expected" URL is used.

What you will do, then, is delete the jolby_dev_static application.

Then, you will create another application, of type "Symbolic Link to Static-Only Application", and use the following path:

/home/USERNAME/webapps/jolby_dev_static/

You can name the Symbolic Link application (which is different from a symbolic link created using "ln -s"!) something like "jolby_dev_static_media".

Then, mount the jolby_dev_static_media application in your Django website record:

/: jolby_dev
/media: jolby_dev_static_media
/media/admin: jolby_dev_admin_media

In this case, you have two symbolic link applications, and no "raw" Static-Only (no .htaccess) applications.

You can mix and match these two applications based on whether you want to point at static files that you don't want to move, or else create a folder that you can drop static media files in:

  • For the former, user a Symbolic Link to Static-Only application.
  • For the latter, use a Static-Only (no .htaccess) application.
permanent link

answered 20 Dec '10, 23:45

ryans ♦♦
5.0k93360
accept rate: 43%

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
×29
×26

question asked: 20 Dec '10, 16:55

question was seen: 5,696 times

last updated: 20 Dec '10, 23:45

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