python-django:在我的views.py中添加数学?

时间:2016-08-12 02:38:32

标签: python django math

我是否需要导入某种模块才能在我的views.py中进行数学运算?

def calc(request):
    if 'pv' in request.GET and 'r' in request.GET:
        pv = request.GET['pv']
        r = request.GET['r']

        calcPV = pv * r
        return render(request, 'main/index.html',
            {
                'pv': pv,
                'r': r,
                'calcPV': calcPV,
            })
    return render(request, 'main/index.html')

出于示例目的,我尝试进行简单的乘法运算:calcPV = pv * r但它不起作用。我做错了吗?

由于

1 个答案:

答案 0 :(得分:0)

您不需要导入任何模块来进行乘法运算。

您可能必须先抛出参数。例如:

pv = int(request.GET['pv'])

在HTML中,您可以显示如下结果:

{{ calcPV }}