在Django中提供图片的问题 [英] Problem with serving pictures in Django
问题描述
在settings.py:
MEDIA_ROOT ='C :/ Users / John / Documents / My Dropbox / Infostuff / filmsite / media /'
MEDIA_URL ='localhost:8000 / static /'
ADMIN_MEDIA_PREFIX ='/ admin-media /'
在urls.py:
(r'^ static /(?P< path>。*)$','django.views.static.serve',
{'document_root':settings.MEDIA_ROOT}),
在模板页面中看起来像这样:
< img src ={{MEDIA_URL}} {{a.picture.url}}>
它被解析为:
< img src =localhost:8000 / static / portrets / 0000138_Leonardo_D.jpg>
当我打开html页面时,它不显示图片(我得到破碎的图片图标) 。如果我去查看源码并复制上面的URL并将其直接转到我的浏览器中,那么 加载图片。我做错了什么?
我使用的是Django 1.2。我还没有使用Apache,因为我首先想要在开发环境中工作。
PS:这是我第一次提问在这个网站上,如果我做错了,请告诉。
使用:
MEDIA_URL ='http:// localhost:8000 / static /'
或
MEDIA_URL ='/ static /'
I'm trying to create my first site in django and I've run into a problem. I'm trying to serve pictures,but it isn't working correctly. I have it set up in the following way:
In settings.py:
MEDIA_ROOT = 'C:/Users/John/Documents/My Dropbox/Infostuff/filmsite/media/'
MEDIA_URL = 'localhost:8000/static/'
ADMIN_MEDIA_PREFIX = '/admin-media/'
In urls.py:
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
It looks like this in the template page:
<img src="{{MEDIA_URL}}{{a.picture.url}}">
And it is parsed to this:
<img src="localhost:8000/static/portrets/0000138_Leonardo_D.jpg">
When I open the html page it doesn't display the pictures (I get the broken picture icon). If I however go to view the source and copy the above url and past it directly into my browser it does load the picture. What am I doing wrong?
I'm using Django 1.2. I'm not using Apache yet, because I would first like to get it working in a development environment.
PS: This is the first time I'm asking a question on this site, if I did something wrong, please tell.
use:
MEDIA_URL = 'http://localhost:8000/static/'
or
MEDIA_URL = '/static/'
这篇关于在Django中提供图片的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!