您好,登錄后才能下訂單哦!
直接上代碼吧:
# views.py def accesslog(request): state = login_status(request.user.is_authenticated()) log_list = AccessLog.objects.all().order_by() paginator = Paginator(log_list, 10) current_page_num = request.GET.get('page', 1) try: current_page = paginator.page(current_page_num) except EmptyPage: current_page = paginator.page(paginator.num_pages) except PageNotAnInteger: current_page = paginator.page(1) return render(request, 'radius/accesslog.html', { 'current_page': current_page, 'paginator': paginator, 'state': state }) # templatetags/mytag.py from django import template register = template.Library() @register.filter(name='substra') def substra(value, arg): try: return int(value) - int(arg) except: return ''
HTML
# accesslog.html {% load mytag %} <div class="container"> <table class="table table-condensed"> {% for log in current_page.object_list %} <tr> <td>{{ log.id }}</td> <td>{{ log.username }}</td> <td>{{ log.ipaddr }}</td> <td>{{ log.access_datetime|date:"Y-m-d H:s" }}</td> {% if log.status %} <td><span class="label label-success">認證成功</span></td> {% else %} <td><span class="label label-danger">認證失敗</span></td> {% endif %} <td>{{ log.message }}</td> </tr> {% endfor %} </table> <nav> {# {{ current_page.paginator.num_pages }}#} <ul class="pagination"> {% if current_page.number > 3 %} <li ><a href="?page=1">第一頁</a></li> {% endif %} {% if current_page.number == 1 %} <li><a href="?page={{ current_page.number }}">1</a></li> {% endif %} {% if current_page.number > 2 %} <li><a href="?page={{ current_page.number|substra:2 }}">{{ current_page.number|substra:2 }}</a></li> <li><a href="?page={{ current_page.previous_page_number }}">{{ current_page.previous_page_number }}</a></li> <li><a href="?page={{ current_page.number }}">{{ current_page.number }}</a></li> {% elif current_page.number == 2 %} <li><a href="?page={{ current_page.previous_page_number }}">{{ current_page.previous_page_number }}</a></li> <li><a href="?page={{ current_page.number }}">{{ current_page.number }}</a></li> {% endif %} {% if current_page.number|add:2 <= current_page.paginator.num_pages %} <li><a href="?page={{ current_page.next_page_number }}">{{ current_page.next_page_number }}</a></li> <li><a href="?page={{ current_page.number|add:2 }}">{{ current_page.number|add:2 }}</a></li> <li><a href="?page={{ current_page.paginator.num_pages }}">最后一頁</a></li> {% elif current_page.number == current_page.paginator.num_pages %} {# nothing to do#} {% elif current_page.number|add:2 >= current_page.paginator.num_pages %} <li><a href="?page={{ current_page.next_page_number }}">{{ current_page.next_page_number }}</a></li> {% endif %} </ul> </nav> </div> </div> {% include 'radius/footer.html' %} <script> $(document).ready(function(){ $('.pagination li a').each(function(){ if ( $(this).html() == {{ current_page.number }} ){ $(this).parent().addClass('active') } }); }) </script>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。