tornadojavascript
1,urls.pycss
import config import os from views.view import IndexHadnler,SearchHadnler,SearchresHadnler class Application(tornado.web.Application): def __init__(self): heandlers = [ (r'/',IndexHadnler), (r'/search',SearchHadnler), (r'/search_res/(?P<page>\d*)',SearchresHadnler), # (r'/pay',PayHadnler) ] super(Application,self).__init__(heandlers,**config.settings,address='0.0.0.0')
2,實現分頁功能及展現html
class Pagination: """ 分頁 """ def __init__(self, current_page='1', page_item=1): all_page, c = divmod(page_item, 5) if c > 0: all_page += 1 try: current_page = int(current_page) except: current_page = 1 if current_page < 1: current_page = 1 self.current_page = current_page # 當前頁 self.all_page = all_page # 總頁數 @property def start(self): """ 顯示數據的起點索引 :return: """ return (self.current_page - 1) * 5 @property def end(self): """ 顯示數據的末尾索引 :return: """ return self.current_page * 5 def page_num_show(self, baseurl): """ 寫入{% raw str_page %}模板中的內容 :param baseurl: 該段代碼不只能夠在/index/中使用,也能夠在/home/等等頁碼使用, :return: 返回一段字符串形式的html代碼塊,包括首頁,頁碼數,上一頁等等內容 """ # 計算9個頁碼的起始索引 list_page = [] if self.current_page <= 4: s = 0 e = min(self.all_page, 9) elif self.current_page > self.all_page - 4: s = max(0, self.all_page - 9) e = self.all_page else: s = self.current_page - 5 e = self.current_page + 4 # 首頁 first_page = '<a href="%s1">首頁</a>' % (baseurl) list_page.append(first_page) # 上一頁current_page-1 if self.current_page <= 1: prev_page = '<a href="javascript:void(0);">上一頁</a>' else: prev_page = '<a href="%s%s">上一頁</a>' % (baseurl, self.current_page - 1) list_page.append(prev_page) #9個頁碼數 for p in range(s, e): if p + 1 == self.current_page: temp = '<a href="%s%s" class="active">%s</a>' % (baseurl, p + 1, p + 1) list_page.append(temp) else: temp = '<a href="%s%s">%s</a>' % (baseurl, p + 1, p + 1) list_page.append(temp) # 下一頁next_page+1 if self.current_page >= self.all_page: next_page = '<a href="javascript:void(0);">下一頁</a>' else: next_page = '<a href="%s%s">下一頁</a>' % (baseurl, self.current_page + 1) list_page.append(next_page) # 尾頁 last_page = '<a href="%s%s">尾頁</a>' % (baseurl, self.all_page) list_page.append(last_page) # # 頁面跳轉 # jump = """<input type="text"/><a οnclick="Jump('%s',this);">go</a>""" % (baseurl,) # script = """<script> # function Jump(url,self){ # var v=self.previousElementSibling.value; # if (v.trim().length>0){ # location.href=url+v; # } # } # </script>""" # list_page.append(jump) # list_page.append(script) str_page = "".join(list_page) return str_page class SearchresHadnler(BaseHandler): async def get(self,page): page_obj = Pagination(page, len(info_res)) # 當前頁顯示的數據 current_list = info_res[page_obj.start:page_obj.end] # 當前頁顯示的頁碼數相關html代碼 str_page = page_obj.page_num_show('/search_res/') self.render('info.html', info=current_list, current_page=page_obj.current_page, str_page=str_page)
3,info.html前端
<!DOCTYPE html> <!-- <html lang="en"> --> <link rel="stylesheet" type="text/css" href="../static/top/gameadmin/libs/aui/css/aui.css" /> <link rel="stylesheet" type="text/css" href="../static/top/gameadmin/libs/aui/css/bootstrap.min.css" /> <link rel="stylesheet" type="text/css" href="../static/top/gameadmin/libs/aui/css/bootstrap-theme.min.css" /> <link type="text/css" rel="stylesheet" href="../static/top/gameadmin/css/jquery.dataTables.min.css"> <link href="../static/top/gameadmin/css/H-ui.min.css" rel="stylesheet" type="text/css" /> <link href="../static/top/gameadmin/css/H-ui.admin.css" rel="stylesheet" type="text/css" /> <script src="../static/top/gameadmin/libs/jquery-1.12.1.min.js" ></script> <script src="../static/top/gameadmin/libs/bootstrap.min.js" ></script> <script src="../static/top/gameadmin/libs/axios.js" ></script> <script src="../static/top/gameadmin/libs/jquery.cookie.js" ></script> <script> var le = { language: { "sProcessing": "處理中...", "sLengthMenu": "顯示 _MENU_ 項結果", "sZeroRecords": "沒有匹配結果", "sInfo": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項", "sInfoEmpty": "顯示第 0 至 0 項結果,共 0 項", "sInfoFiltered": "(由 _MAX_ 項結果過濾)", "sInfoPostFix": "", "sSearch": "搜索:", "sUrl": "", "sEmptyTable": "表中數據爲空", "sLoadingRecords": "載入中...", "sInfoThousands": ",", "oPaginate": { "sFirst": "首頁", "sPrevious": "上頁", "sNext": "下頁", "sLast": "末頁" } } } </script> <head> <!-- <meta charset="UTF-8"> --> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <!-- <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/> --> <!-- <meta name="format-detection" content="telephone=no,email=no,date=no,address=no"> <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="expires" content="0" /> --> <title>碩果電影</title> </head> <body> <!-- <div class="aui-content aui-margin-b-15"> --> <section class="container-fluid page-404 minWP text-c" style="height: 20px;"> <p class="error-title"> <span class="va-m"> 電影列表</span> </p> </section> <div class="container" style="margin-top: 70px"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <table id="dt" style="border:black 3px solid" class="table table-hover"> <thead><tr class="warning"><td>影片名稱</td><td>影片類別</td><td>更新時間</td><td>播放</td></tr></thead> <tbody> {% for i in info %} <tr> <td>{{i['title']}}</td> <td>{{i['typ']}}</td> <td>{{i['update_time']}}</td> <td> {%for j in i['info_url']%} <a href="{{j['url']}}">{{j['name']}}</a> {%end%} </td> </tr> {%end%} </tbody> </table> <div class="page_num"> {% raw str_page %} </div> </div> </div> </div> </div> <script type="text/javascript" src="../static/top/gameadmin/js/jquery.dataTables.min.js" ></script> <script type="text/javascript"> $(document).ready(function() { "bFilter": true, //過濾功能 $("#dt").DataTable( // "bFilter": true,//過濾功能 // 'bLengthChange': false,//改變每頁顯示數據數量 le, ); }) </script> </body> </html>
效果以下:java
Djangojquery
1,前端ios
<nav aria-label="Page navigation"> <div class="pagination"> <ul class="pagination"> {% if books.has_previous %} <a class='active' href="?page={{ books.previous_page_number }}">上一頁</a> {% endif %} <!-- {% for num in books.paginator.page_range%} {%if pindex == books.number%} <a href="">{{ num }}</a> {%else%} <a href="/books/borrow_show/{{num}}">{{ num }}</a> {%endif%} {% endfor %} --> <span class="current"> 第{{ books.number }}頁</span> {% if books.has_next %} <a class='active' href="?page={{ books.next_page_number }}">下一頁</a> {% endif %} 共{{ books.paginator.num_pages }}頁 </ul> </div> </nav>
2,後端web
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage, InvalidPage class My_player(View): @method_decorator(check_login) def get(self,request): res = request.COOKIES.get("token") ret = Account.objects.filter(uuid=int(res)).first() result = Friendscircle.objects.filter(accountid=ret.id).first() #玩家信息 info = Friendscircleaccount.objects.filter(fcircleid=result.id).values('accountid') id_list = [] for i in info: if i['accountid'] != ret.id: id_list.append(i['accountid']) book_list = Account.objects.filter(id__in=id_list) paginator = Paginator(book_list, 5) page = request.GET.get('page') try: books = paginator.page(page) # todo: 注意捕獲異常 except PageNotAnInteger: # 若是請求的頁數不是整數, 返回第一頁。 books = paginator.page(1) except InvalidPage: # 若是請求的頁數不存在, 重定向頁面 return HttpResponse('找不到頁面的內容') except EmptyPage: # 若是請求的頁數不在合法的頁數範圍內,返回結果的最後一頁。 books = paginator.page(paginator.num_pages) return render(request,'myPlayer.html', {'books': books})