首页 > 其他 > 详细

12.02

时间:2019-12-02 20:16:16      阅读:68      评论:0      收藏:0      [点我收藏+]

Ajax结合sweetalert实现删除按钮动态效果

下载bootstrap-sweetalet项目

通过复制粘贴动态框样式,在自己进行修改即可使用

bulk_create批量插入数据

普通方式批量插入多条数据:

for i in range(1000):
    models.book.objects.create(title = f'第{i}本书')

运行速度极慢

bulk_create批量插入多条数据:

book_list = []
for i in range(1000):
    book.list.append(models.book(title=f'第{i}本书')
models.book.objects.bulk_create(book_list)

与普通方法差距很大,运行速度很快

自定义分页器

后端

book_queryset = models.book.objects.all() # 想要分页展示的数据
current_page = request.GET.get('page',1) # 获取当前页
all_count=book_queryset.count() # 查看一共有多少条数据
page_queryset = book_quyerset[page_obj.start:page_obj.end]
return render(request.'index.html',local())

前端

{% for book in page_queryset %} 将页面上原本的queryset全部换成切片之后的queryset即可
    <p>{{book}}</p>
{% endfor %}
{{page_obj.page_html|safe}} #告诉这是安全的可以读取

12.02

原文:https://www.cnblogs.com/maqiaobin/p/11972749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!