首页下载和文章调用查询方法实战演示
views.py
def index(request):
if request.method == 'GET':
video_lists = Video_List.objects.all().order_by('video_list_order')
softs = Download.objects.all().order_by('down_time')[:3]
arts = Art.objects.all().order_by('art_time')[:10]
# 侧边栏
tags = Side.side_tags
new_arts = Side.side_new_arts
hot_arts = Side.side_hot_arts
context = {'video_lists': video_lists, 'softs': softs, 'arts': arts, 'tags': tags, 'new_arts': new_arts, 'hot_arts': hot_arts}
return render(request, 'index.html', context=context)
index.html
<!-- 工具下载 开始 -->
<div class="main ">
<div class="mainbar">
<div class="title_h2">
<h2>资源下载</h2>
<a href="/tool/" title="PyQt5开发环境_PyQt5开发工具下载" target="_blank">查看更多...</a>
</div>
<div class="content">
<ul>
{% for soft in softs %}
<li class="item_gj">
<div class="img_gj">
<img src="/media/{{ soft.down_ico }}" alt="{{ soft.down_title }}">
</div>
<div class="gj_text">
<div class="name">{{ soft.down_title }}</div>
<a href="/pycharm.html" title="{{ soft.down_title }}"><i class="iconfont icon-xiazai "></i>点击下载</a>
<span>{{ soft.soft_kb }}MB</span>
</div>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
<!-- 工具下载 结束 -->
<!-- 技术笔记 开始 -->
<div class="main">
<div class="mainbar main_note">
<div class="title_h2">
<h2>博客文章</h2>
<a href="/blog/" title="博客文章">查看更多...</a>
</div>
</div>
<div class="content">
<ul>
{% for art in arts %}
<li class="note clearfix">
<a href="/xuanze.html" class="img fl">
<img src="/media/{{ art.art_img }}" alt="{{ art.art_title }}">
</a>
<div class="note_text fr">
<div class="title">
<a href="/artlist-{{ art.art_top_list.art_list_tail }}/" class="lanmu"><i></i>{{ art.art_top_list.art_list_short_title }}</a>
<h3 class="">
<a href="/xuanze.html" title="{{ art.art_title }}">{{ art.art_title }}</a>
</h3>
</div>
<div class="icons">
<span><i class="iconfont icon-zuozhe" ></i>{{ art.art_author }}</span>
<span><i class="iconfont icon-time"></i>{{ art.art_time }}</span>
<span><i class="iconfont icon-dianji" ></i>{{ art.art_click }}</span>
</div>
<p>{{ art.art_description }}</p>
</div>
</li>
{% endfor %}
</ul>
</div>
</div>
<!-- 技术笔记 结束 -->