多平台统一管理软件接口,如何实现多平台统一管理软件接口
645
2022-09-06
django分页(Django分页查询如何实现)
border="1px">
ID 名称 操作
{% for cls in paginator_data.object_list %}
{% endfor %}
{% if paginator_data.has_previous %}
{% endif %}
{% for page in paginator_data.paginator.page_range %}
{% if paginator_data.number == page %}
{{ page }}
{% else %}
{% endif %}
{% endfor %}
{% if paginator_data.has_next %}
{% endif %}
新增
{% include 'modal_classes.html' %}
$('#btn_delete').click(function () {
id = $('#btn_delete').val();
alert(id)
url = '/del_classes/'+ id
type = 'DELETE'
data = {}
$.ajax({
type: type,
url: url,
data: data,
dataType: "json",
success: function(data){
//逻辑
console.log(data)
location.reload()
},
error: function(){
//显示错误信息
},
})
})
$('#btn_add').click(function () {
var title = $('#class_name').val()
var data = {title:title}
type = 'POST' // GET,POST,DELETE,PUT, ...
url = '/del_classes/'
$.ajax({
type: type,
url: url,
data: data,
dataType: "json",
success: function(result){
//逻辑
console.log(result)
status = result.status
if (status == 1){
location.reload()
} else if (status == 0){
alert('重复创建')
}
},
error: function(){
//显示错误信息
},
})
})
class del_classes(ListView): model = Classes paginate_by = 10 template_name= 'get_classes.html' def delete(self,request,*args,**kwargs): print(kwargs) pk = kwargs.get('pk') print(pk) Classes.objects.filter(id=pk).delete() return JsonResponse({'status':1}) def post(self,request,*args,**kwargs): data = QueryDict(request.body).dict() print(data) Classes.objects.create(**data) print(data) return JsonResponse({'status': 1}) def handle_page(self, page, object_list): paginator = Paginator(object_list, self.paginate_by, 1) try: paginator_data = paginator.page(page) except PageNotAnInteger: paginator_data = paginator.page(1) except EmptyPage: paginator_data = paginator.page(paginator.num_pages) return paginator_data def get(self, request, *args, **kwargs): pk = kwargs.get('pk') if pk: try: instance = self.model.objects.get(pk=pk) return render(request, 'get_classes.html', {'cls': instance}) #return render(request, self.template_detail, instance.to_dict) except self.model.DoesNotExist: return JsonResponse({'data':'id {} not exits'.format(pk)}) object_list = self.get_queryset() page = request.GET.get('page',1) paginator_data = self.handle_page(page, object_list) search = request.GET.get('search', '') return render(request, self.template_name, {'paginator_data': paginator_data, 'search': search})
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~