Django - 服务媒体值错误
我正在尝试在我的开发环境中提供用户上传的媒体文件。
#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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议尝试遵循 的文档开发中的静态托管
, 'serve'), )编辑:
您的字典应该在
'document_root'
和 <代码>设置.MEDIA_ROOTI'd recommend trying to follow the docs for static hosting in development
, 'serve'), )EDIT:
Your dictionary should have a
:
not,
between the'document_root'
andsettings.MEDIA_ROOT