HTML 模板 与 Views.py 的更改
1 , banner
views.py
def index(request):
#轮播图
#获取banner
banner_list = Banner.objects.all()
# 传参方法(1)
ctx = {
'banner_list':banner_list,
}
return render(request, 'blog/index.html',ctx)
# 传参方法(2)
return render(request, 'blog/index.html',locals())
index.html
<div class="carousel-inner" role="listbox">
{% for banner in banner_list %}
{% if banner.is_active %}
<div class="item active">
<a href="#" target="_blank" title="木庄网络博客源码">
<img src="/{{ banner.cover }}" alt="木庄网络博客源码" class="img-responsive"></a>
</div>
{% else %}
<div class="item">
<a href="#" target="_blank" title="专业网站建设">
<img src="/{{ banner.cover }}" alt="专业网站建设" class="img-responsive"></a>
</div>
{% endif %}
{% endfor %}
</div>
网友评论