//顶部搜索栏搜索方法
function search_click(){
var type = $('#jsSelectOption').attr('data-value'),
keywords = $('#search_keywords').val(),
request_url = '';
if(keywords == ""){
return
}
if(type == "course"){
request_url = "/course/list?keywords="+keywords
}else if(type == "teacher"){
request_url = "/org/teacher/list?keywords="+keywords
}else if(type == "org"){
request_url = "/org/list?keywords="+keywords
}
window.location.href = request_url
}
C:\Users\hlg\PycharmProjects\MxOnline\templates\base.html
{% load staticfiles %}
{% block title %}慕学在线首页{% endblock %}
{% block custom_css %}{% endblock %}
{% block custom_bread %}
- 首页>
{% endblock %}
{% block content %}
{% endblock %}
{% block custom_js %}{% endblock %}
class TeacherListView(View):
"""
课程讲师列表页
"""
def get(self, request):
all_teachers = Teacher.objects.all()
# 教师搜索
search_keywords = request.GET.get('keywords', "")
if search_keywords:
# i 表示不区分大小写
# Q 是python提供的或功能
all_teachers = all_teachers.filter(Q(name__icontains=search_keywords)|
Q(work_company__icontains=search_keywords)|
Q(work_position__icontains=search_keywords))
sort = request.GET.get('sort', "")
if sort:
if sort == "hot":
all_teachers = all_teachers.order_by("-click_nums")
sorted_teacher = Teacher.objects.all().order_by("-click_nums")[:3]
# 对课程机构进行分页
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
# 一定要3个参数,不然报错
p = Paginator(all_teachers, 5, request=request)
teachers = p.page(page)
return render(request, "teachers-list.html",{
"all_teachers": teachers,
"sorted_teacher": sorted_teacher,
"sort": sort
})