Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.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中如何将值从一个HTML传递到另一个HTML_Python_Html - Fatal编程技术网

在python中如何将值从一个HTML传递到另一个HTML

在python中如何将值从一个HTML传递到另一个HTML,python,html,Python,Html,有两个html文件mypage.html和page.html,想要将一些值从一个html传递到另一个html,在另一个html中如何获取这些值 我正在使用的代码: with open('page.html', 'w') as myFile: myFile.write('<html>') myFile.write('<body>') myFile.write('<table>') myFile.write('<tr>

有两个html文件mypage.html和page.html,想要将一些值从一个html传递到另一个html,在另一个html中如何获取这些值

我正在使用的代码:

 with open('page.html', 'w') as myFile:
    myFile.write('<html>')
    myFile.write('<body>')
    myFile.write('<table>')
    myFile.write('<tr>')
    myFile.write('<td> Interface </td>')
    myFile.write('<td> Global </td>')
    myFile.write('</tr>')
    myFile.write('<tr>')

    myFile.write('<td> <a href="interface.html">Interface</a></td>')
    myFile.write('<td> <a href="global.html">Global</a></td>')
    myFile.write('</% print c /%>')
    #myFile.write('<var>params</var>')
    myFile.write('</tr>')
    myFile.write('</table>')
    myFile.write('</body>')
    myFile.write('</html>')

#render HTML page
with open('mypage.html', 'w') as myFile:
    myFile.write('<html>')
    myFile.write('<body>')
    myFile.write('<table>')
    myFile.write('<tr>')
    myFile.write('<td> Host Name </td>')
    myFile.write('<td> Result </td>')
    myFile.write('</tr>')
    myFile.write('<tr>')
    c = Cookie.SimpleCookie()
    c['mycookie'] = 'cookie_value'        
    myFile.write('<td> <a href="page.html?params="'+final_dict.keys()[0]+ '>'+final_dict.keys()[0]+'</a></td>')
    myFile.write('<td> Fail</td>')
    myFile.write('</tr>')
    myFile.write('</table>')
    myFile.write('</body>')
    myFile.write('</html>')
打开('page.html','w')作为myFile的
:
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
myFile.write('Interface')
myFile.write('Global')
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
#myFile.write('params')
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
#呈现HTML页面
将open('mypage.html','w')作为myFile:
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
myFile.write('主机名')
myFile.write('Result')
myFile.write(“”)
myFile.write(“”)
c=Cookie.SimpleCookie()
c['mycookie']='cookie\u值'
myFile.write(“”)
myFile.write('Fail')
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)
myFile.write(“”)

您可以使用php中的内置数组
$\u get
获取URL参数

要从URL检索参数,您可以将此PHP代码插入网页的html源代码(您正在打开的网页包含URL中的数据):



当然,您可以使用PHP来处理这些数据。只有在启用PHP的web服务器上运行网页时,这才有效。

您有一个生成html的python脚本。那很好

您正在将html保存到一个文件中,然后呢?提供文件?我猜你只生成一次文件,然后就有了静态文件。当用户实际请求url时,不会执行python代码。你应该彻底改变这种观念

您希望发生的是:

  • 用户在浏览器中键入url
  • 浏览器向服务器发送请求
  • 服务器执行一些python生成html,但不将其保存到文件中。它只是将其发送回用户
  • 用户可以看到生成的html
  • 使用这种方法,在步骤3中,每次都会执行python脚本,您有机会读取请求参数

    现在,要做到这一点,您需要一个服务器

    您可以使用绝对低级的方法,通过将python作为CGI脚本执行来配置Apache、IIS或其他任何服务.py文件的工具。这与你目前正在做的事情非常相似。如果你这样做,你会学到很多关于HTTP如何工作的知识,但这是一条艰难的道路,而且不是最佳性能

    更好的选择

    您可以运行一个pythonweb服务器,该服务器调用python函数为每个配置的url提供服务。看一看,然后。烧瓶很好,但CherryPy可能更适合初学者


    我建议你从CherryPy开始。按照文档,查找教程…

    这个问题是关于浏览器中的操作还是python生成脚本?要在服务器端处理“值”是什么意思?您是否可以在第1页的文本框中键入内容?您是否考虑过使用@bobsterman:也就是说,这一行(')将创建链接并转到page.html。在page.html中,希望具有'final_dict.keys()[0]的值'
    <?php
     echo $_GET['key'] // Will print out the data of the given key
    ?>