在python中拥有客户端的地址 [英] Have the address of the client in python
本文介绍了在python中拥有客户端的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的要求是:我的网页是用python创建的(其中有html代码),每个页面都有一个按钮可以转到下一页。
例如,当我们提交html表单时,是否可以获取客户端的地址?
我的意思是,要进入客户端的URL地址。
My request is : I have my web pages created in python (wherein there is html code), each pages has a button to go to the next page. Is it possible to get the address of the client when we submit an html form for example ? I mean, to have into the URL address of the client.
如果可能,我会显示我的代码,否则我会删除我的问题。
If that possible, I'll show my code, else I delete my question.
这是我的 html 代码:
ip = cgi.escape(os.environ["REMOTE_ADDR"])
<html>
path install: ${install_path}<br/><br/>
os: ${os}<br/><br/>
unix user: ${user_name}<br/><br/>
<form name="sd" method="get" action="ip/cgi/scriptGet.py">
Name: <input type="text" name="name"><br/><br/>
Pseudo: <input type="text" name="pseudo"/><br/><br/>
<input type="submit" value="OK"/>
</form>
这里我的 python代码:
import os, sys, platform, getpass, tempfile
import webbrowser
import string
import json
import cgi, cgitb, os
def main( server_IP,install_path):
template = open('scriptHmtl.phtml').read()
contenu = string.Template(template).substitute(
install_path = install_path,
os = user_os,
user_name = user_login
)
if __name__ == "__main__":
server_IP = sys.argv[1]
install_path = sys.argv[2]
main(server_IP,install_path)
推荐答案
您可以使用 cgi
和 REMOTE_ADDR
并使用如下:
You can use cgi
and REMOTE_ADDR
and use like this :
cgi.escape(os.environ["REMOTE_ADDR"])
将其放入变量并将变量调用为html的操作m ....
Put that in a variable and call the variable into action of your html form ....
这篇关于在python中拥有客户端的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文