I've got this media root:
MEDIA_ROOT = '/var/www/hosted/myapp/static/'and this media url
MEDIA_URL = '/static/res/'and I am trying to upload a file using a callable:
def get_uploadto(instance, filename): ''' Dummy callable to silence the upload_to field of FileFields ''' return os.path.开发者_StackOverflow中文版join('uploads', filename), it uploads the picture on the disk in /var/www/hosted/myapp/static/uploads/ just as planned, but in the admin it creates a link poiting to static/res/uploads, which does not exist. Does anyone know why? Of course, I can simply move the uploads dir within static res, but I am looking for a more elegant solution.
This is the expected behaviour. The files are in
MEDIA_ROOT + 'uploads' + filename
or
/var/www/hosted/myapp/static/uploads/filename
the URL's that point to those files are:
MEDIA_URL + 'uploads' + filename
or
/static/res/uploads/filename
You then need to make sure that your application or hosting environment points the URL to the on disk location. In the dev environment you would have something like this in your urlpatterns:
(r'^static/res/(?P<path>.*)$', 'django.views.static.serve', {'document_root': os.path.dirname(settings.MEDIA_ROOT)}),
精彩评论