[英]how to pull url and pass variable to python 3's http.server
My google-fu is failing me, perhaps because it is late. 我的Google Fu令我失望,也许是因为它来晚了。
Given the code below, I need to take everything after the domain.tld/ and parse it. 给定下面的代码,我需要将所有内容都放在domain.tld /之后并进行解析。 It will then run against a database (in the example I'm using a dict, but in reality I'll be making a call to mysql, will that change it?) 然后它将针对数据库运行(在示例中,我使用的是dict,但实际上我将调用mysql,这会改变它吗?)
Then, it will serve up a redirect header with that url. 然后,它将使用该网址提供重定向标头。
from http.server import BaseHTTPRequestHandler, HTTPServer
class HTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(301)
self.send_header('Location', url)
self.end_headers()
return
array["stuff"] = "http://google.com"
array["thing"] = "http://yahoo.com"
url = array[page]
server_address = ('0.0.0.0', 80)
httpd = HTTPServer(server_address, HTTPServer_RequestHandler)
httpd.serve_forever()
可能有点晚了,但是根据文档 , self.path
应该在服务器位置之后返回url。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.