我在非常簡單的操作中遇到了非常奇怪的問題。models.pyNbProducts(models.Model): brand = models.CharField(max_length=45, blank=True, null=True) name = models.CharField(max_length=45, blank=True, null=True) cluster = models.CharField(max_length=45, blank=True, null=True) target_market = models.CharField(max_length=10, blank=True, null=True) cpu_vendor = models.CharField(max_length=45, blank=True, null=True) base_platform = models.CharField(max_length=45, blank=True, null=True) gpu_list = models.CharField(max_length=45, blank=True, null=True) screen_size = models.CharField(max_length=45, blank=True, null=True) screen_resulution_list = models.CharField(max_length=45, blank=True, null=True) touchscreen = models.CharField(max_length=45, blank=True, null=True)views.py list_Products = NbProducts.objects.\ filter(id__in=products_for_execute).\ values('brand', 'name', 'id')# list_Products:#<QuerySet [{'brand': 'Acer', 'name': 'Aspire R7-372T', 'id': 2713}, #{'brand': 'Acer', 'name': 'Aspire S7-393', 'id': 2716}, #{'brand': 'Acer', 'name': 'Swift SF514-51', 'id': 2743},.... class FProducts(object): def __init__(self, id, brand, name): self.id = str(id), self.brand = str(brand), self.name = str(name) print(self.id, self.brand, self.name) fproducts = list() for i in list(list_Products): fproducts.append(FProducts(id=i['id'], brand=i['brand'], name=i['name']))>> {'2713',) ('Acer',) 'Aspire R7-372T'>> {'2716',) ('Acer',) 'Aspire S7-393'>> {'2743',) ('Acer',) 'Swift SF514-51'所以。沒有任何命令,它會(huì)將兩個(gè)參數(shù) - 'id' 和 'brand' 放入元組中。參數(shù)“名稱” - 好吧,只是字符串。我不t need Tuple. And I don明白有什么關(guān)系。另外我把這個(gè)放進(jìn)去。 self.id = self.id[0] self.brand = self.brand[0]好的,有幫助,應(yīng)用程序可以工作。但我看不到問題的根源。這是Python(3.7)還是Django(2.1.7)的問題?
1 回答

茅侃侃
TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超21個(gè)贊
您自己在這里創(chuàng)建了一個(gè)元組:
self.id = str(id), self.brand = str(brand), self.name = str(name)
應(yīng)該:
self.id = str(id) self.brand = str(brand) self.name = str(name)
添加回答
舉報(bào)
0/150
提交
取消