Django - 服务媒体值错误

发布于 2024-11-15 03:59:15 字数 886 浏览 8 评论 0原文

我正在尝试在我的开发环境中提供用户上传的媒体文件。

#settings.py
#[...]
import os
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
MEDIA_ROOT = (os.path.join(SITE_ROOT, 'media/'))
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
  os.path.join(SITE_ROOT, 'static/'),
)
#[...]

#url.py
urlpatterns = patterns('',
  #[...]
  url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve',
    {'document_root', settings.MEDIA_ROOT}
  ),
  url(r'^%s(?P<path>.*)$' % settings.STATIC_URL[1:], 'django.views.static.serve',
    {'document_root', settings.STATIC_ROOT}
  ),
)

尝试访问上传的文件,例如 http://127.0.0.1:8000/media/videos /julian_06.flv,我明白了

/media/videos/julian_06.flv 处的值错误

字典更新序列元素#0的长度为40;需要2个

I'm trying to serve user uploaded media files in my dev environment.

#settings.py
#[...]
import os
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
MEDIA_ROOT = (os.path.join(SITE_ROOT, 'media/'))
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
  os.path.join(SITE_ROOT, 'static/'),
)
#[...]

#url.py
urlpatterns = patterns('',
  #[...]
  url(r'^%s(?P<path>.*)

Trying to access an uploded file like http://127.0.0.1:8000/media/videos/julian_06.flv, I get

ValueError at /media/videos/julian_06.flv

dictionary update sequence element #0 has length 40; 2 is required

% settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root', settings.MEDIA_ROOT} ), url(r'^%s(?P<path>.*)

Trying to access an uploded file like http://127.0.0.1:8000/media/videos/julian_06.flv, I get

ValueError at /media/videos/julian_06.flv

dictionary update sequence element #0 has length 40; 2 is required

% settings.STATIC_URL[1:], 'django.views.static.serve', {'document_root', settings.STATIC_ROOT} ), )

Trying to access an uploded file like http://127.0.0.1:8000/media/videos/julian_06.flv, I get

ValueError at /media/videos/julian_06.flv

dictionary update sequence element #0 has length 40; 2 is required

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似狗非友 2024-11-22 03:59:15

我建议尝试遵循 的文档开发中的静态托管

if settings.DEBUG:
urlpatterns += patterns('django.contrib.staticfiles.views',
    url(r'^media/(?P<path>.*)

编辑:

您的字典应该在 'document_root' 和 <代码>设置.MEDIA_ROOT

urlpatterns = patterns('',
url(r'^%s(?P<path>.*)
, 'serve'),
)

编辑:

您的字典应该在 'document_root' 和 <代码>设置.MEDIA_ROOT


 % settings.MEDIA_URL[1:], 'django.views.static.serve',
    {'document_root': settings.MEDIA_ROOT}),
)
, 'serve'), )

编辑:

您的字典应该在 'document_root' 和 <代码>设置.MEDIA_ROOT

I'd recommend trying to follow the docs for static hosting in development

if settings.DEBUG:
urlpatterns += patterns('django.contrib.staticfiles.views',
    url(r'^media/(?P<path>.*)

EDIT:

Your dictionary should have a : not , between the 'document_root' and settings.MEDIA_ROOT

urlpatterns = patterns('',
url(r'^%s(?P<path>.*)
, 'serve'),
)

EDIT:

Your dictionary should have a : not , between the 'document_root' and settings.MEDIA_ROOT


 % settings.MEDIA_URL[1:], 'django.views.static.serve',
    {'document_root': settings.MEDIA_ROOT}),
)
, 'serve'), )

EDIT:

Your dictionary should have a : not , between the 'document_root' and settings.MEDIA_ROOT

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文