WebFaction
Community site: login faq

I'm a little confused by your docs on configuring Django because you don't seem to differentiate between STATIC and MEDIA, whereas the Django docs indicate that STATIC should be for project img/css/js etc while MEDIA should be separate for user-uploaded media.

It makes sense that the webfaction static app would serve both project css/js/img and user-uploaded media but I'm not sure how to achieve this in my settings since Django does not allow STATIC_ROOT and MEDIA_ROOT to be the same.

My current settings are:

STATIC_ROOT = '[path to static app]'
STATIC_URL = 'http://my.domain/static/'
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')
MEDIA_URL = ''

It looks like my static files are working fine as I've run collectstatic but my user-uploaded media is not being found. I've tried putting in 'http://my.domain/media/' for media URL with no luck.

Thanks!

asked 18 Aug '12, 16:02

sharkfin
27159
accept rate: 0%

edited 18 Aug '12, 16:02


You can actually set up another static app to serve your media files. Just set it up the same way as you did for your static media and point it to the directory for your user uploaded media files. Then serve it on the /media url for example. Be sure to add that app to your website entry in the control panel as well.

permanent link

answered 18 Aug '12, 16:18

bmeyer71 ♦♦
1.5k3613
accept rate: 33%

That was it, thanks!

(18 Aug '12, 16:41) sharkfin

bmeyer71, I have set up my /static and /media settings & directories as you describe but only the static files are being collected. The /media files are not being collected. I have a media app called my_media and a static app called my_static and they are both linked to my website in the control panel under /media and /static, respectively (as explained above). My /my_proj/my_proj/settings.py looks like this:

MEDIA_ROOT = '/home/username/webapps/my_media/' MEDIA_URL = 'http://testsite.username.webfactional.com/media/'

STATIC_ROOT = '/home/username/webapps/my_static/' STATIC_URL = 'http://testsite.username.webfactional.com/static/'

STATICFILES_DIRS = ( '/home/username/webapps/django/my_proj/static', )

My static directory is at: /my_proj/static My media directory is at: /my_proj/media

When I run "python2.7 manage.py collectstatic" all static files are collected into webapps/my_static as expected but media files are not collected into webapps/my_media. Another thing that puzzles me is that I have to add /path/to/static/ in my STATICFILES_DIRS list whereas I thought django should just pick them up automatically without adding that directory to that list. Could it be because my static directory is /my_proj/static/ instead of the default /my_proj/my_proj /static/? Could this also be the reason for the failure to collect media files? How can I fix this (other than the obvious rearrangement of directories)?

(21 Oct '12, 15:37) Roland

Collectstatic only works on your static files. MEDIA_ROOT/MEDIA_URL are for user uploaded files and are not collected by that command. See Django's docs here.

(21 Oct '12, 15:46) bmeyer71 ♦♦

So how do /media files get into the /my_media static file app (or should they)?

(21 Oct '12, 16:05) Roland

The location specified for MEDIA_ROOT/MEDIA_URL are for files uploaded by you or our users. eg: images used for a blog post.

(21 Oct '12, 16:10) bmeyer71 ♦♦

I guess what I am trying to ask is do user-uploaded images get copied to static files server for the sake of efficiency? If so, how does that happen?

(21 Oct '12, 16:14) Roland

They do not. The only purpose of the collectstatic command is to collect the static files from the various applications that make up your project and serve them from a single location. The uploaded files that get placed in MEDIA_ROOT are served from that location.

(21 Oct '12, 16:19) bmeyer71 ♦♦

Created an account just to say thank you bmeyer. Spent 4 hours trying to figure static/media/deployment issue out.

(20 Oct '16, 02:04) travbum
showing 5 of 8 show 3 more comments
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:

×26
×22
×8

question asked: 18 Aug '12, 16:02

question was seen: 15,797 times

last updated: 20 Oct '16, 02:04

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