当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Getting numeric inputs and calculating

问题描述:

I'm trying to create a code which calculates the Normal density using 3 numeric inputs. I tried to run the following code, but the website does not receive inputs and jumps to the the last comment, 'Thank you.' How could I fix it? Thanks in advance!

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!')

网友答案:

I think it's maybe because you don't return what you get but only a Thanks.

Change last line to this:

...
            html= '<html><body>The density is %s.</body></html>' % density

    return HttpResponse(html)
...
分享给朋友:
您可能感兴趣的文章:
随机阅读: