我正在尝试创建一个使用3个数字输入计算Normal浓度的代码。我尝试运行以下代码,但网站没有收到输入并跳转到最后一条评论,“谢谢。”我该怎么办呢?提前谢谢!
from django.shortcuts import render
from django import forms
from django.http import *
from scipy.stats import norm
class NF(forms.Form):
n1 = forms.FloatField(label = 'Input a Number')
n2 = forms.FloatField(label = 'Mean')
n3 = forms.FloatField(label = 'SD')
def cal(request):
if request.method == 'POST':
form = NF(request.POST)
if form.is_valid():
number = form.clean_data['n1']
mean = form.clean_data['n2']
sd = form.clean_data['n3']
density = norm.pdf(number, mean, sd)
html= '<html><body>The density is %s.</body></html>' % density
return HttpResponse('Thanks!')
答案 0 :(得分:0)
我认为这可能是因为你没有归还你得到的东西而只是谢谢。
将最后一行更改为:
...
html= '<html><body>The density is %s.</body></html>' % density
return HttpResponse(html)
...