我正在使用Python和CGI进行维护。该网站目前运行在Python上,但出于某种奇怪的原因,我必须将Python变量分配给 到同一个Python文件中的JavaScript变量。我尝试了很多东西,但他们都没有工作,我不知道是否有可能这样做。任何帮助将不胜感激。我简化了代码,以显示从Python到JavaScript的变量交换。我的Python版本是3.5.2,并且该站点在IIS服务器上运行。再次感谢您的帮助和时间。将Python变量分配给JavaScript变量
import cgi
print('')
temp = 78 #These is the Python variable I need to assign to the Javascript variable.
print('<html>')
print('<script type="text/javascript">')
print('var x = {{temp}};') #Here's how I'm trying to assign the python variable.
print('document.write(x);')
print('document.write("HELLO PYTHON VARIABLE!!");')
print('</script>')
print('</html>')
是它只是一个数字,或不变量保持用户输入? (因为那时涉及安全) – RemcoGerlich