Python 如何将django变量导入html?
我必须从rs232端口发送数据,并使用java脚本将其显示在图形中 我需要在html中导入views.py变量的帮助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
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。