没有找到Django媒体URL [英] Django media URL not found
问题描述
错误跟踪跟踪:
使用myapp中定义的URLconf。 url,Django按照以下顺序尝试了这些URL模式:
1. ^ media \ /(?P< path>。*)$
当前的URL〜 myapp / media / image.jpg,没有匹配任何这些。
我的应用程序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
<$ p $从django.conf导入设置
从django.conf.urls.static导入静态
urlpatterns = patterns('',
)+ static(settings.MEDIA_URL,document_root = settings.MEDIA_ROOT)
任何人都可以建议我解决方案为此。
谢谢。
经过这么多路径,最后我修复了问题。问题与媒体文件的权限有关。尝试访问这些媒体文件的过程是root和文件由用户自己拥有。有一个内核补丁可以防止这些类型的访问。所以404错误作为响应返回。
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.
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
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
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. There's a kernel patch that prevents these type of accesses.So why 404 error is returning as response.
这篇关于没有找到Django媒体URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!