亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我仍然得到“DeferredAttribute”對象沒有屬性“對象”?

為什么我仍然得到“DeferredAttribute”對象沒有屬性“對象”?

aluckdog 2023-06-13 14:58:03
經過幾天的尋找,我仍然無法跨過這個障礙。我只是想打印一份來自賣家的描述列表作為視圖。這就是我正在使用的...models.py:from django.db import modelsclass Sellers(models.Model):    index = models.BigIntegerField(blank=True, null=False)    seller = models.TextField(db_column='SELLER', blank=False, null=False,                          primary_key=True)    block = models.TextField(db_column='BLOCK', blank=False, null=False)      street = models.TextField(db_column='STREET', blank=False, null=False)      space = models.TextField(db_column='SPACE', blank=False, null=False)     description = models.TextField(db_column='DESCRIPTION', blank=True, null=True)    document_with_idx = models.TextField(blank=False, null=False)     document_with_weights = models.TextField(blank=False, null=False)class Meta:    managed = False    db_table = 'Sellers'def __str__(self):    return self.index'''views.py:from django.http import HttpResponsefrom search.models import Sellersdef search(request):    output = Sellers.description.objects.all()    return HttpResponse(output)'''任何方向將不勝感激,我覺得我已經閱讀了與此相關的所有相關帖子。我想是時候用我的確切設置發布問題了。謝謝!
查看完整描述

1 回答

?
MYYA

TA貢獻1868條經驗 獲得超4個贊

Sellers.description指的是字段,所以你基本上得到的是對象,而不是對象中的TextField一個,因為它是一個類,而不是一個對象。您可以通過以下方式獲取值:descriptionsSellersSellersdescription


from django.http import JsonResponse

from search.models import Sellers


def search(request):

    output = Sellers.objects.values_list('description', flat=True)

    return JsonResponse({'data': list(output)})

此外,您不能簡單地將其包裝在 a 中HttpResponse,因為它需要一個類似字符串/字節的對象。例如,您可以使用 JSON 對其進行編碼JsonResponse。


查看完整回答
反對 回復 2023-06-13
  • 1 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號