|
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:
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! |
|
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. That was it, thanks! 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)? 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. So how do /media files get into the /my_media static file app (or should they)? The location specified for MEDIA_ROOT/MEDIA_URL are for files uploaded by you or our users. eg: images used for a blog post. 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? 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.
showing 5 of 7
show all
|