Javascript Django使用plotly和表单中的数据绘制图形

Javascript Django使用plotly和表单中的数据绘制图形,javascript,python,django,plot,plotly,Javascript,Python,Django,Plot,Plotly,我想使用plotly.js库绘制图形,图形的输入通过html表单从用户处获取 我创建了一个html表单来读取绘图的X和Y值。在views.py中,我使用request.POST.get访问表单数据,然后将其添加到列表x[],y[] from django.shortcuts import render x=[] y=[] def index(request): return render(request,'home.html') def inputplot(request):

我想使用plotly.js库绘制图形,图形的输入通过html表单从用户处获取

我创建了一个html表单来读取绘图的X和Y值。在views.py中,我使用request.POST.get访问表单数据,然后将其添加到列表x[],y[]

from django.shortcuts import render
x=[]
y=[]
def index(request):
    return render(request,'home.html')

def inputplot(request):
    if(request.method=="POST"):
       xvalue=request.POST.get('xvalue')
       yvalue=request.POST.get('yvalue')
       x.append(xvalue)
       y.append(yvalue)
       print x
       print y
       return render(request,'inputplot.html')
       del x[:]
       del y[:]
       return render(request,'inputplot.html')
def plot(request):
       `return render(request,'plot.html',{'x':x,'y':y})
我想要plot.html中的列表,但当我向列表中添加数据时,它会自动添加一些字符。例如,我为x值输入了一个数字12,但该数字在列表中显示为[u'12']

为什么会这样


请给我一个解决方案或给我展示另一种读取用户数据和绘制值的方法。???“帮助我”

您的
请求中的数据。这里的POST
是一个字符串。
[u'12']
正在告诉您这一点,这就是它无法正确绘制的原因

假设它们都是整数,则需要符合以下条件的内容:
xvalue=int(request.POST.get('xvalue'))


如果合适,用十进制替换

来自
请求的数据。POST
是一个字符串。
[u'12']
正在告诉您这一点,这就是它无法正确绘制的原因

假设它们都是整数,则需要符合以下条件的内容:
xvalue=int(request.POST.get('xvalue'))


如果合适,用十进制替换

太好了!如果你能接受这个答案,我将不胜感激伟大的如果你能接受这个答案,我将不胜感激