简体   繁体   中英

serving static files from heroku

I have created a simple portfolio website on 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.

My site is running fine and displaying the images correctly on my local dev server(127.0.0.1:8000)

However, on manojmj.herokuapp.com I can see only the markup and no images. When I click the image url I get the errror:

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

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'}),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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