Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将django变量导入html?_Python_Html_Django_Serial Port - Fatal编程技术网

Python 如何将django变量导入html?

Python 如何将django变量导入html?,python,html,django,serial-port,Python,Html,Django,Serial Port,我必须从rs232端口发送数据,并使用java脚本将其显示在图形中 我需要在html中导入views.py变量的帮助 views.py import io from django.http import HttpResponse from django.shortcuts import render from random import sample def about(read): import serial, time arduino = seri

我必须从rs232端口发送数据,并使用java脚本将其显示在图形中

我需要在html中导入views.py变量的帮助

views.py
import io
from django.http import HttpResponse
from django.shortcuts import render
from random import sample

    def about(read):
        import serial, time
        arduino = serial.Serial('COM3', 115200)
        time.sleep(2)
        read = arduino.readline()
        arduino.close()
        read = int(read)
        return HttpResponse(str(read), '')
Html

var updateChart = function (count) {
    count = count || 1;
    for (var j = 0; j < count; j++) {
<!-- this is where I try to read the variable -->
        yVal = href="{% 'about' %}"
        dps.push({
            x: xVal,
            y: yVal
        });
        xVal++;
    }
var updateChart=函数(计数){
计数=计数| | 1;
对于(var j=0;j
将此内容写在您的视图上,并指向它的url

from django.shortcuts import render
def indexw(request):
    context_variable = ''
    context = {"context_variable": context_variable}
    return render(request,'index.html', context)

在你的视图上写下这个,并指向它的url

from django.shortcuts import render
def indexw(request):
    context_variable = ''
    context = {"context_variable": context_variable}
    return render(request,'index.html', context)

定义URL模式,将此URL模式映射到视图,在此视图中呈现HTML模板。在此之前,您必须确定您的“值”是否应该是映射到视图的URL(因为您正在将其分配/比较到
href
)或者视图中的计算结果。实际上,您的问题中没有HTML-它是JS。定义URL模式,将此URL模式映射到视图,在此视图中呈现HTML模板。在此之前,您必须确定您的“值”是否应该是映射到视图的URL(因为您正在将其分配/比较到
href
)或视图中的计算结果。实际上,您的问题中没有HTML-它是JS。