int()参数必须是字符串,类似字节的对象或数字,而不是“方法" [英] int() argument must be a string, a bytes-like object or a number, not 'method'
本文介绍了int()参数必须是字符串,类似字节的对象或数字,而不是“方法"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在django 1.8/python 3.4
In django 1.8 /python 3.4
我该怎么办int的方法?
How can I do method to int?
示例:
models.py
models.py
class Bid(models.Model):
bid_Price = models.IntegerField(default=1)
def __str__(self):
return self.bid_Price
def topPrice(self):
return 100
view.py
def BidView(request, bid_id):
bid_data = Bid.objects.get(id=bid_id)
if int(bid_data.topPrice_text) < 100):
推荐答案
方法的编写方法已经返回一个int,因此您实际上需要调用该方法以使用其返回值:
The way it's written your method is already returning an int, so what you would have to do is actually call the method to use its return value:
if bid_data.topPrice()<100:
我不得不说我不太了解您要在这里做什么,但是 topPrice
可能无论如何都不应该是一种方法.
I do have to say that I don't quite know what you're trying to do here, but topPrice
probably shouldn't be a method anyways.
这篇关于int()参数必须是字符串,类似字节的对象或数字,而不是“方法"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文