我是否需要导入某种模块才能在我的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
但它不起作用。我做错了吗?
由于
答案 0 :(得分:0)
您不需要导入任何模块来进行乘法运算。
您可能必须先抛出参数。例如:
pv = int(request.GET['pv'])
在HTML中,您可以显示如下结果:
{{ calcPV }}