-1
渲染图像看我的GitHub如何在Django的模板
https://github.com/rg3915/gallery
如何呈现在Django的模板图像? 但他将返回:
画廊
媒体/ 3665_1280x800_8UX8tgG.jpg
环法自行车赛
媒体/ 281405_fSRBDZu.jpg孩子
的
自行车如何呈现图像?
是否错误是在settings.py
渲染图像看我的GitHub如何在Django的模板
https://github.com/rg3915/gallery
如何呈现在Django的模板图像? 但他将返回:
画廊
媒体/ 3665_1280x800_8UX8tgG.jpg
环法自行车赛
媒体/ 281405_fSRBDZu.jpg孩子
的
自行车如何呈现图像?
是否错误是在settings.py
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from gallery.core.views import *
from django.contrib import admin
urlpatterns = patterns(
'gallery.core.views',
url(r'^$', 'home', name='home'),
url(r'^gallery/$', GalleryList.as_view(), name='gallery_list'),
url(r'^admin/', include(admin.site.urls)),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
MEDIA_ROOT = BASE_DIR.child('media')
MEDIA_URL = '/media/'
STATIC_ROOT = BASE_DIR.child('staticfiles')
STATIC_URL = '/static/'
<html>
<body>
<h1>Gallery</h1>
{% if gallery %}
{% for photo in gallery %}
<p><img src="{{ photo.photo.url }}" width="300px"></p>
<p>{{ photo.description }}</p>
{% endfor %}
{% endif %}
</body>
</html>
秘密是photo.photo.url
谢谢,谢谢,谢谢!我一直在研究这个问题超过一个小时,而你的问题已经解决了我的问题(并且很快)。 – allardbrain 2016-06-09 19:03:21