在本篇文章里小编给大家整理的是关于django中瀑布流写法实例代码以及相关知识点,有需要的朋友们学习参考下。
django中瀑布流初探
img.html
Title姑娘们
11
22
33
44
views
def imgs(request): # img_list = models.Img.objects.all() return render(request,'img.html') def get_imgs(request): nid = request.GET.get('nid') img_list = models.Img.objects.filter(id__gt=nid).values('id','src','title') img_list = list(img_list) ret = { 'status': True, 'data': img_list } # return HttpResponse(json.dumps(ret)) return JsonResponse(ret) # return JsonResponse([11,22,33],safe=False)
models
class Img(models.Model): src = models.FileField(max_length=32,verbose_name='图片路径',upload_to='static/upload') title = models.CharField(max_length=16,verbose_name='标题') summary = models.CharField(max_length=128,verbose_name='简介') class Meta: verbose_name_plural = '图片' def __str__(self): return self.title