class VideoDetailView(DetailView):
queryset = Video.objects.all()
class VideoListView(ListView):
paginate_by = 10 # <app>/<modelname>_list.html
def get_queryset(self, *args, **kwargs):
qs = Video.objects.all()
print(self.request.GET)
query = self.request.GET.get("q", None)
if query is not None:
qs = qs.filter(
Q(Video_Description__icontains=query) | Q(videofile__icontains=query))
return qs
def get_context_data(self, *args, **kwargs):
context = super(VideoListView, self).get_context_data(*args, **kwargs)
return context
video_list.html 文件是:
{% extends "base.html" %}
{% load static %}
<body>
<link rel="stylesheet" href="{% static 'deploy/cafeteria_cut.mp4' %} ">
{% block content %}
{% include "result/navbar.html" %}<br/>
{% include "result/sidebar.html" %}<br/>
{% include "result/calendar.html" %}<br/>
<div style="margin-left: 10%">
<button type="button" class="btn btn-secondary btn-lg"><a href="{% url 'deploy:create' %}" style='color:white'>Upload Video</a></button>
</div>
{% for object in object_list %}
<div class="container" style="margin-left: 10%; align-items: center;">
<h2>
</br>
<a href="{{ object.get_absolute_url }}">
{{ object.Video_Description }}
</a>
</br>
</h2>
</br>
<a href="" style="align-items: center;">
{{ object.videofile}}
</a>
</br>
<br><br>
<video width='400' controls>
<source src="{% static 'deploy/youtubeVideo_cut20.mp4' %}" type='video/mp4'>
Your browser does not support the video tag.
</video>
<br><br>
{% empty %}
{% if request.GET.q %}
<p style="padding-left: 20%; font-size: 70px">No Result Found </p>
{% else %}
<p style="padding-left: 20%; font-size: 70px"> No Result Yet.
{% endif %}
{% endfor %}
{% endblock content %}
非常抱歉,我没有在我的 video_list.html 文件中提及一件非常重要的事情:
<br><br>
<video width='400' controls>
<source src="{% static 'deploy/youtubeVideo_cut20.mp4' %}" type='video/mp4'>
Your browser does not support the video tag.
</video>
<br><br>
<br><br>
<video width='400' controls>
<source src="{{ object.videofile.url }}" type='video/mp4'>
Your browser does not support the video tag.
</video>
<br><br>