如何从python中修改html格式的文本 [英] how to modify text in html form from python
问题描述
我正在尝试从python更改表单字段中的数据。以下
代码不会崩溃,但没有效果,就好像形式一样只是
原始html表单的副本。
我必须重新创建表单才能这样做吗?
我的观点是客户能够重新读取修改后的数据。
谢谢,
Philippe
#!/ usr / bin / python
导入cgi
导入os
导入系统
导入日志记录
import cgi
sys.stderr = sys.stdout
print" Content-type:text / html\\\
"
尝试:
form = cgi.FieldStorage()
#logging.warning(表格)
除外:
logging.exception(" \ nEXCECEPTION 1")
试试:
form [''tosrv ''] .value =" TEST"
除外:
logging.exception(" \ nEXCEPTION 2")
pass
< html>
< body>
< title>智能登录< / title>
< h1>智能登录< / h1>
< hr>
< FORM METHOD = POST ACTION =" /cgi-bin/scfbweb.py">
< table>
< TR>< TD>
< INPUT TYPE = HIDDEN NAME =" key" VALUE =" process"
TO SERVER:< BR>
< INPUT type = text NAME =" tosrv"值= QUOT;至" size = 60>
< BR>
FROM SERVER< BR>
< INPUT type = text name =" fromsrv"值= QUOT; FROM" size = 60>
< P>
< INPUT TYPE =" SUBMIT" VALUE =" START">
< / TD>< / TR>< / table>
< / FORM>
< / body>
< / html>
Hi,
I am trying to change the data in a form field from python. The following
code does not crash but has no effect as if "form" is just a copy of the
original html form.
Must I recreate the form order to do that ?
My point is for the client to be able to re-read the modified data.
Thanks,
Philippe
#!/usr/bin/python
import cgi
import os
import sys
import logging
import cgi
sys.stderr = sys.stdout
print "Content-type: text/html\n"
try:
form = cgi.FieldStorage()
#logging.warning (form)
except:
logging.exception("\nEXCEPTION 1")
try:
form[''tosrv''].value = "TEST"
except:
logging.exception("\nEXCEPTION 2")
pass
<html>
<body>
<title>Smart Logon</title>
<h1>Smart Logon</h1>
<hr>
<FORM METHOD=POST ACTION="/cgi-bin/scfbweb.py">
<table>
<TR><TD>
<INPUT TYPE=HIDDEN NAME="key" VALUE="process">
TO SERVER:<BR>
<INPUT type=text NAME="tosrv" value="TO" size=60>
<BR>
FROM SERVER<BR>
<INPUT type=text name="fromsrv" value="FROM" size=60>
<P>
<INPUT TYPE="SUBMIT" VALUE="START">
</TD></TR></table>
</FORM>
</body>
</html>
推荐答案
PS:如果我的问题目前尚不清楚,我正试图分享
客户端和服务器之间的形式。
就像许多站点允许您修改现有数据一样:
1 )服务器弹出一个包含你数据的表格。
2)客户可以修改并提交。
我知道这是一个_basic_问题对不起。
Philippe
Philippe C. Martin写道:
PS: If my question is not clear, I am trying to "share" the form between the
client and server.
just as many sites out there allow you to modify existing data:
1) the server pops up a form with your data in it.
2) the client can modify it and submit.
I know this is a _basic_ question, sorry.
Philippe
Philippe C. Martin wrote:
我正在尝试从python更改表单字段中的数据。以下
代码不会崩溃,但没有效果,就好像形式一样。只是
原始html表单的副本。
我必须重新创建表单顺序吗?
我的观点是让客户能够重新阅读修改后的数据。
谢谢,
Philippe
#!/ usr / bin / python
导入cgi
import os
import sys
import logging
import cgi
sys.stderr = sys.stdout
print" Content-type:text / html\\\
" ;
尝试:
form = cgi.FieldStorage()
#logging.warning(form)
除外:
logging.exception(" \\ \\ n \\ nEXEXCEPTION 1")
尝试:
形式[''tosrv'']。value =" TEST"
除了:
logging.exception(" \ nEXEXCEPTION 2")
< html>
< body>
< title>智能登录< / title>
< ; h1>智能登录< / h1>
< hr>
< FORM METHOD = POST ACTION =" /cgi-bin/scfbweb.py">
< table>
< TR>< TD>
< INPUT TYPE = HIDDEN NAME =" key" VALUE =" process"
TO SERVER:< BR>
< INPUT type = text NAME =" tosrv"值= QUOT;至" size = 60>
< BR>
FROM SERVER< BR>
< INPUT type = text name =" fromsrv"值= QUOT; FROM" size = 60>
< P>
< INPUT TYPE =" SUBMIT" VALUE =" START"
< / TD>< / TR>< / table>
< / FORM>
< / body>
< / html>
Hi,
I am trying to change the data in a form field from python. The following
code does not crash but has no effect as if "form" is just a copy of the
original html form.
Must I recreate the form order to do that ?
My point is for the client to be able to re-read the modified data.
Thanks,
Philippe
#!/usr/bin/python
import cgi
import os
import sys
import logging
import cgi
sys.stderr = sys.stdout
print "Content-type: text/html\n"
try:
form = cgi.FieldStorage()
#logging.warning (form)
except:
logging.exception("\nEXCEPTION 1")
try:
form[''tosrv''].value = "TEST"
except:
logging.exception("\nEXCEPTION 2")
pass
<html>
<body>
<title>Smart Logon</title>
<h1>Smart Logon</h1>
<hr>
<FORM METHOD=POST ACTION="/cgi-bin/scfbweb.py">
<table>
<TR><TD>
<INPUT TYPE=HIDDEN NAME="key" VALUE="process">
TO SERVER:<BR>
<INPUT type=text NAME="tosrv" value="TO" size=60>
<BR>
FROM SERVER<BR>
<INPUT type=text name="fromsrv" value="FROM" size=60>
<P>
<INPUT TYPE="SUBMIT" VALUE="START">
</TD></TR></table>
</FORM>
</body>
</html>
Philippe C. Martin写道:
Philippe C. Martin wrote:
PS:如果我的问题目前尚不清楚,我正试图分享
客户端和服务器之间的形式。
同样多的站点允许您修改现有数据:
1)服务器弹出一个表单,其中包含您的数据。
2)客户可以修改并提交。
我知道这是一个_basic_问题,对不起。
PS: If my question is not clear, I am trying to "share" the form between the
client and server.
just as many sites out there allow you to modify existing data:
1) the server pops up a form with your data in it.
2) the client can modify it and submit.
I know this is a _basic_ question, sorry.
什么时候调试Python cgi脚本,从
命令行运行脚本是有帮助的,以确保没有任何编译器错误。根据
如何设置服务器,如果你的
脚本不能编译,你会收到服务器错误或只是一个空白页面。当我按照我的建议直接运行你的脚本时,这就是我得到的
:
pmcnett @ sol:〜
When debugging Python cgi scripts, it is helpful to run the scripts from a
command line just to make sure there aren''t any compiler errors. Depending on
how the server is set up, you''ll get a server error or just a blank page if your
script won''t compile. When I run your script directly as I suggest, here''s what
I get:
pmcnett@sol:~
python test.py
文件" test.py",第23行
< html>
^
语法错误:语法无效
D''哦!您需要用引号括住html以使其成为字符串,如:
print""
< html>
....
< / html>
"""
I我真的不明白你原来的问题,但也许这将有助于你再次滚动
。
-
Paul McNett
http://paulmcnett.com
http://dabodev.com
python test.py
File "test.py", line 23
<html>
^
SyntaxError: invalid syntax
D''oh! You needed to surround the html with quotes to make it a string, as in:
print """
<html>
....
</html>
"""
I don''t really understand your original problem, but perhaps this will help get
you rolling again.
--
Paul McNett
http://paulmcnett.com
http://dabodev.com
这篇关于如何从python中修改html格式的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!