Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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文本区域默认值与页面混乱_Python_Html - Fatal编程技术网

Python html文本区域默认值与页面混乱

Python html文本区域默认值与页面混乱,python,html,Python,Html,我有一个python cgi脚本,它创建一个文本区域,并用文件内容中的默认值填充它。这曾经奏效,但最近我注意到随着文件内容的变化;html呈现不正确,提交按钮和要在文本区域显示的文件内容的某些部分(作为默认内容)等丢失或与整个页面的html混淆 print('<form action="x.cgi" method="post">') print('<textarea name="textcontent" cols="120" rows="50">')

我有一个python cgi脚本,它创建一个文本区域,并用文件内容中的默认值填充它。这曾经奏效,但最近我注意到随着文件内容的变化;html呈现不正确,提交按钮和要在文本区域显示的文件内容的某些部分(作为默认内容)等丢失或与整个页面的html混淆

 print('<form action="x.cgi" method="post">')
        print('<textarea name="textcontent" cols="120" rows="50">')
        with open('somefile', 'r') as content_file:
            content = content_file.read()
        content_file.close()
        print(content)
        print('</textarea>')
        print('<HR>')
        print('<input type="submit" value="Submit" />')
        print('</form>')
打印(“”)
打印(“”)
以open('somefile','r')作为内容文件:
content=content\u file.read()
content_file.close()
打印(内容)
打印(“”)
打印(“
”) 打印(“”) 打印(“”)

可以做些什么,以使某个文件的内容不会与html表单混淆。请注意,somefile是一个配置文件,我需要打印文件中的所有内容,以便用户可以进行必要的更改并提交它

,因为您将
一起使用,所以
content\u file.close()
行是多余的,尽管不是问题所在。我看不出代码有任何问题:文件的内容确实会弄乱HTML语法。有办法吗。我尝试使用urllib.quote;但正如我提到的,我需要在文本区域中完整地保存文件的内容。或者可能用python对内容进行加密/编码,并使用javascript对内容进行解密/解码等(只是一个想法),请参见