[英]TypeError Error during template rendering
我看不到您的代碼的 rest(從 Orders 類返回的def __str__
)。 但在我看來,您正試圖將 Object 作為字符串返回。
即:您希望將創建的 object 的__str__
屬性顯示為您的外鍵產品“整個對象”。
但是您不能將 object 'Product' 作為字符串返回。 當你這樣做時,認為這就是你正在做的事情:
def __str__(self):
return self.product # <-- This is an the object, not a string or the __str__ property
您將在 memory 中返回 object 地址,並且由於 object 尚不存在,因此它返回 None。
嘗試將您的回報轉換為顯式字符串
def __str__(self):
return str(self.product) # <-- Returns the __str__ of the FK Object.
或嘗試返回已經是字符串的屬性
def __str__(self):
return self.product.name # <-- Returns the attribute from the FK Object.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.