简体   繁体   English

从heroku提供静态文件

[英]serving static files from heroku

I have created a simple portfolio website on manojmj.herokuapp.com 我在manojmj.herokuapp.com上创建了一个简单的投资组合网站

I want to host the images,css etc on heroku itself and does not want to move to s3 since its only 800kb in size. 我想在heroku本身上托管图像,css等,并且不希望移动到s3,因为它只有800kb的大小。

My site is running fine and displaying the images correctly on my local dev server(127.0.0.1:8000) 我的网站运行良好,并且在本地开发服务器上正确显示了图像(127.0.0.1:8000)

However, on manojmj.herokuapp.com I can see only the markup and no images. 但是,在manojmj.herokuapp.com上,我只能看到标记,而看不到图像。 When I click the image url I get the errror: 单击图像URL时出现错误:

ValueError at /static/images/me.jpg
dictionary update sequence element #0 has length 35; 2 is required
Request Method: GET
Request URL:    http://www.manojmj.com/static/images/me.jpg
Django Version: 1.4.3
Exception Type: ValueError
Exception Value:    
dictionary update sequence element #0 has length 35; 2 is required
Exception Location: /app/.heroku/python/lib/python2.7/site-      packages/django/core/urlresolvers.py in resolve, line 207
Python Executable:  /app/.heroku/python/bin/python
Python Version: 2.7.4
Python Path:    
['/app',
 '/app/.heroku/python/bin',
 '/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.36-py2.7.egg',
 '/app/.heroku/python/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
 '/app',
 '/app/.heroku/python/lib/python27.zip',
 '/app/.heroku/python/lib/python2.7',
 '/app/.heroku/python/lib/python2.7/plat-linux2',
 '/app/.heroku/python/lib/python2.7/lib-tk',
 '/app/.heroku/python/lib/python2.7/lib-old',
 '/app/.heroku/python/lib/python2.7/lib-dynload',
 '/app/.heroku/python/lib/python2.7/site-packages',
 '/app/.heroku/python/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
 Server time:   Fri, 21 Jun 2013 09:37:01 -0500

my urls.py 我的urls.py

url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root:   settings.STATIC_ROOT'}),
url(r'^static/css/(?P<path>.*)$','django.views.static.serve',{'document_root: settings.STATIC_ROOT'}),
url(r'^static/images/(?P<path>.*)$','django.views.static.serve','document_root: settings.STATIC_ROOT'),
url(r'^static/js/(?P<path>.*)$','django.views.static.serve',{'document_root: settings.STATIC_ROOT'}),
url(r'^hello/', 'manojmjapp.views.hello'),

url(r'^$', 'manojmjapp.views.home'),

try to change this line : 尝试更改此行:

url(r'^static/images/(?P<path>.*)$','django.views.static.serve','document_root: settings.STATIC_ROOT'),

for this: 为了这:

url(r'^static/images/(?P<path>.*)$','django.views.static.serve',{'document_root': 'settings.STATIC_ROOT'}),

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

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