这是我在 django 1.4 项目中配置MEDIA_ROOT
和设置的方式:STATIC_ROOT
SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) ## from http://www.morethanseven.net/2009/02/11/django-settings-tip-setting-relative-paths/
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media') ## from http://www.morethanseven.net/2009/02/11/django-settings-tip-setting-relative-paths/
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
我的目录结构是这样的:
--myproject
----myapp
----media ## where I expect the images
----myproject ##(settings.py, urls.py, etc.)
但是图像被保存到myproject
文件夹内的另一个目录中:
--myproject
----myapp
----media
----myproject
------media ## this is where the files end up
因此,这些文件没有被包括在内。以下是网址:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns() ## from http://stackoverflow.com/questions/10216827/django-static-files-wont-load
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,}))
如何修复我的配置,以便显示用户上传的媒体文件?感谢您的任何想法!