如何在Django temp上渲染图像

2024-10-01 13:38:47 发布

您现在位置:Python中文网/ 问答频道 /正文

查看我的GitHub

https://github.com/rg3915/gallery

如何在Django模板上渲染图像? 但他回来了:

画廊

介质/3665 U 1280x800 U 8UX8tgG.jpg公司在

环法自行车赛

媒体/281405_fSRBDZu.jpg在

儿童自行车

如何渲染图像?在

虫子在吗设置.py在


Tags: djangohttps图像githubcom模板公司画廊
1条回答
网友
1楼 · 发布于 2024-10-01 13:38:47

在网址.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)

在设置.py在

^{pr2}$

画廊_列表.html在

<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

相关问题 更多 >