gpt4 book ai didi

django-templates - 如何在 Django 模板上渲染图像

转载 作者:行者123 更新时间:2023-12-05 01:02:41 25 4
gpt4 key购买 nike

查看我的 GitHub

https://github.com/rg3915/gallery

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

图库

媒体/3665_1280x800_8UX8tgG.jpg

环法自行车赛

媒体/281405_fSRBDZu.jpg

child 自行车

如何渲染图像?

bug 是否在 settings.py 中

最佳答案

urls.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)

settings.py

MEDIA_ROOT = BASE_DIR.child('media')
MEDIA_URL = '/media/'

STATIC_ROOT = BASE_DIR.child('staticfiles')
STATIC_URL = '/static/'

gallery_list.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

关于django-templates - 如何在 Django 模板上渲染图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29383311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com