繁体   English   中英

如何使用python将数据从一页传输到另一页

[英]how to transfer data from onepage to another using python

我想将数据从一个页面传输到另一页面,例如我的登录详细信息显示在另一页面中,那我该怎么办

我的Python服务器代码:

    from SimpleHTTPServer import SimpleHTTPRequestHandler
    import BaseHTTPServer
    from urlparse import urlparse, parse_qs


    class CustomHTTPRequestHandler(SimpleHTTPRequestHandler):

        def do_POST(self):
            try:
                length = int(self.headers.getheader('content-length'))
                data = self.rfile.read(length)
                self.send_response(200, "OK")
                print data.split('&')
                #process_data(data, self.client_address)
            except Exception as inst:
                logging.error(type(self).__name__ + "/" + type(inst).__name__ + " \
    (" + inst.__str__() + ")")

    if __name__ == '__main__':
        BaseHTTPServer.HTTPServer(('\
    ', 8544), CustomHTTPRequestHandler).serve_forever()

我的HTML的第一个文件index.html

<form action="" method="POST">
                        User Name :
                            <input type="text"id="username" name="username" placeholder="Enter User Name">
                        Password  :
                            <input type="password" id="password" name="password" laceholder="Enter Password">
                            <button type="submit" id="submit">Sign in</button>
                        </div>
                    </div>
                </form>

在第二个HTML文件(index2.html)中,我要显示输入到index.html

为此,我搜索了很多线程,但没有成功找到,或者某些我不理解,因此请帮助我对服务器进行什么更改或进行其他操作。

执行此操作的标准方法是使用基于cookie的会话。 也就是说,在初始请求时,Web服务器为客户端提供会话cookie。 该cookie将在浏览会话期间存储在用户的Web浏览器中。

所有后续的HTTP请求都包含该会话ID(基本上是一个随机的,不可猜测的字符串)。 然后,服务器使用该会话ID来检索与特定客户端相关联的服务器上的任何信息(例如购物车的内容)。

我建议您在这里阅读有关cookie的信息: http : //en.wikipedia.org/wiki/HTTP_cookie

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM