首页视频查询接口开发逻辑讲解
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>PyQt5视频教程</h2>
<div class="_as">
<!--<a href="/designer/" title="Qt Designer" target="_blank">Qt Designer</a>-->
</div>
</div>
<!-- 视频教程 -->
{% for video_list in video_lists %}
<div class="video_arc">
<div class="title_h3">
<h3>第{{ forloop.counter }}章:{{ video_list.video_list_title }}</h3>
<a href="/base/" title="{{ video_list.video_list_title }}">查看更多...</a>
</div>
<ul class="courses">
{% for video in video_list.video_set.all|dictsort:"video_order" %}
<li class="course_item">
<i class="iconfont icon-shipin"></i>
<div class="course_cont">
<span>第{{ forloop.counter }}课:</span>
<a href="/start.html" title="{{ video.video_title }}">{{ video.video_title }}</a>
</div>
<div class="item_left">
<span class="time">{{ video.video_long }}分钟</span>
</div>
</li>
{% endfor %}
</ul>
</div>
{% endfor %}
</div>
</div>
<!-- 视频教程 结束 -->