【发布时间】:2016-09-21 11:45:25
【问题描述】:
我正在尝试使用 Django 作为后端的动态分页来实现 css3 中的样式。我不知道如何实现它,因为在添加表单以获得用户偏好时,我无法使其工作。也很难使用 css3 来完全重建表单删除按钮组选项以获得分页。
Views.py:
class ProductListView(ListView):
model = Product
paginate_by = 12
def get_paginate_by(self, queryset):
return self.request.GET.get('paginate_by', self.paginate_by)
原始模板 HTML5 代码:
<div class="filter-show btn-group">
<label data-translate="collections.toolbar.show">Show</label>
<button class="btn btn-2 dropdown-toggle" data-toggle="dropdown">
<i class="icon-exchange"></i>
<span>12</span>
<i class="icon-chevron-down"></i>
</button>
<ul class="dropdown-menu" role="menu">
<li class="active" ><a href="12">12</a></li>
<li ><a href="16">16</a></li>
<li ><a href="32">32</a></li>
<li ><a href="all" data-translate="collections.toolbar.all">All</a></li>
</ul>
</div>
我想做的是:
<div class="filter-show btn-group">
<label>Show</label>
<button class="btn btn-2 dropdown-toggle" >
<i class="icon-exchange"></i>
<span>12</span>
<i class="icon-chevron-down"></i>
</button>
<form action="" method="get">
<select class="dropdown-menu" role="menu" name="paginate_by">
<option class="active" ><a href="12">12</a></option>
<option><a href="16">16</a></option>
<option><a href="32">32</a></option>
<option><a href="all" data-translate="collections.toolbar.all">All</a></option>
</select>
</form>
</div>
相关css代码如下:
<style>
.toolbar .btn-group.filter-show { margin-left: 10px; }
.toolbar button.dropdown-toggle {
float: none;
border: 1px solid #cbcbcb;
color: #505050;
background: #fff;
line-height: 34px;
padding: 0 50px 0 10px;
position: relative;
text-transform: capitalize;
width: 170px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.toolbar .filter-show button.dropdown-toggle {
width: 120px;
}
.btn-group>.btn:last-child:not(:first-child), .btn-group>.dropdown-toggle:not(:first-child) {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
</style>
在 HTML5 端有两种类型的视图。第一个按钮是网格,第二个按钮是左侧的列表。因此,如果用户选择网格,则“显示”区域中的所有列都将更改为 12、16、32 等网格。如果选择列表,则相应地列出 12、16、32 和所有。 让我知道解决方案。
【问题讨论】:
标签: django html css django-templates django-views