简体   繁体   English

找不到Django媒体网址

[英]Django media URL not found

I'm running into a strange issue,hope some where else some one can had faced the same problem.My problem which is like, the stored media in django application are not able to serve through MEDIA_ROOT URL.When I tried to get list of media files that are saved in my application using URL myhost/media/ it showing all the media files.But when I tried to view on of them using URL myhost/media/image.jpg, got error Requested page not found. 我遇到了一个奇怪的问题,希望有些人可以面对同样的问题。我的问题就像,django应用程序中存储的媒体无法通过MEDIA_ROOT URL服务。当我试图获取列表时使用URL myhost / media /显示所有媒体文件保存在我的应用程序中的媒体文件。但是当我尝试使用URL myhost / media / image.jpg查看它们时,得到错误请求的页面未找到。

Error Track Trace: 错误跟踪跟踪:

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.

My app settings.py 我的app settings.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',
)

Urls.py Urls.py

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',

) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Can any one suggest me solution for this. 任何人都可以建议我解决这个问题。

Thanks. 谢谢。

After so many trails,finally I have fixed the issue.The problem is related to permission of media files.The process that's trying to access these media files is root and the files are owned by the user itsme. 经过这么多小道,最后我解决了这个问题。问题与媒体文件的许可有关。试图访问这些媒体文件的过程是root,文件归用户所有。 There's a kernel patch that prevents these type of accesses.So why 404 error is returning as response. 有一个内核补丁阻止了这种类型的访问。所以404错误作为响应返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM