我需要在模板中获取数据。
我有ajax请求:
$(".retailer-list-img").mouseover(function () {
var $this = $(this);
var category_id = $this.attr('id');
$.ajax({
'url': '/shop/getfeatured/',
'method': 'POST',
'data': {'category_id': category_id,},
'success': function(response){
console.log(response)
}
});
});
视图.py
def MerchantGetfeaturedView(request):
featured = Merchant.objects.filter(
is_catalog_active=1,
is_active=1,
category_id=request.REQUEST.get('category_id'),
date_deleted__isnull=True
).select_related('_image')
featured = serializers.serialize('json', featured)
return HttpResponse(featured, content_type="application/json")
但是有没有相关的对象“图像”?如何序列化相关模型?谢谢。