如何使用:来自django的“未来”进口部门

如何使用:来自django的“未来”进口部门,django,django-templates,Django,Django Templates,我正在尝试使用django的\uuuuu future\uuuuu import division进行操作,但在my views.py中无法使用 在django shell下,与python shell相同: >>> from __future__ import division >>> result = 37 / 3 >>> result 12.333333333333334 >>> 当我尝试使用django view

我正在尝试使用django的
\uuuuu future\uuuuu import division
进行操作,但在my views.py中无法使用

在django shell下,与python shell相同:

>>> from __future__ import division
>>> result = 37 / 3
>>> result
12.333333333333334
>>> 
当我尝试使用django views.py时,它也不起作用

error message: unsupported operand type(s) for /: 'int' and 'instancemethod'
views.py:

from __future__ import division

def show_product(request, product_slug, template_name="product.html"):
    review_total_final = decimal.Decimal('0.0')
    review_total = 0
    product_count = product_reviews.count # the number of product rated occurences
    if product_count == 0:
        return review_total_final
    else:
        for product_torate in product_reviews:
            review_total += product_torate.rating
            review_total_final = review_total / product_count
            return review_total_final
    return review_total_final
models.py:

class ProductReview(models.Model):
    RATINGS =((5,5),.....,)
    product = models.ForeignKey(Product)
    rating = models.PositiveSmallIntegerField(default=5, choices=RATINGS)
    content = models.TextField()
产品审查是一个查询集


任何帮助

来自未来进口部门的
与此无关;您试图将一个值除以方法本身,而不是首先调用该方法来获得正确的操作数。比较和对比:

>>> class X(object):
...   def count(self):
...     return 1
... 
>>> x = X()
>>> 1 / x.count
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'int' and 'instancemethod'
>>> 1 / x.count()
1
>>X类(对象):
...   def计数(自身):
...     返回1
... 
>>>x=x()
>>>1/x.count
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:/:“int”和“instancemethod”的操作数类型不受支持
>>>1/x.计数()
1.

您能在views.py中显示用法吗?views.py def show_product(请求、产品、模板名称=“product.html”):review_total_final=decimal.decimal('0.0'))review_total=0 product_count=product_reviews.count#如果product_count=0,则产品评级发生的次数:return review_total_final其他:对于product_torate in product_review:review_total+=product_torate.rating review_total_final=review_total/product_count#review#_total_final=Ratestar.objects.filter(rate__gte=F(review_total)/F(product_count))return review_total_final有很多错误。count可能应该是.count(),可能与.rating和.rating()相同,但缩进真的很奇怪,不能说出来。这是count而不是count(),请在说错话之前尝试一下。好的,请您展示一下您的产品审查模型?评分字段的类型是什么?