Reg*_*lva 1 django-templates imagefield
看我的GitHub
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)
Run Code Online (Sandbox Code Playgroud)
MEDIA_ROOT = BASE_DIR.child('media')
MEDIA_URL = '/media/'
STATIC_ROOT = BASE_DIR.child('staticfiles')
STATIC_URL = '/static/'
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
秘密是 photo.photo.url
| 归档时间: |
|
| 查看次数: |
3753 次 |
| 最近记录: |