我遇到了一个奇怪的问题,希望其他人也遇到过同样的问题。我的问题是,django 应用程序中的存储媒体无法通过 MEDIA_ROOT URL 提供服务。当我尝试获取列表时使用 URL myhost/media/ 保存在我的应用程序中的媒体文件,它显示了所有媒体文件。但是当我尝试使用 URL myhost/media/image.jpg 查看它们时,出现错误 Requested page not found。
错误跟踪:
Using the URLconf defined in myapp.urls, Django tried these URL patterns, in this order:
1.^media\/(?P<path>.*)$
The current URL, ~myapp/media/image.jpg, didn't match any of these.
我的应用设置.py
MEDIA_ROOT = '/home/itsme/myapp/media/'
MEDIA_URL = '/media/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
)
网址.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
任何人都可以建议我解决这个问题。
谢谢。