Attention ! Cet interpréteur n’est pas totalement compatible avec Python3.
import http.server
import urllib.parse
FORMULAIRE = '''<form target="/" method="get">
<input type="text" name="identifiant"/>
<input type="submit" />
</form>'''
class TestHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
html = FORMULAIRE
if '?' in self.path:
path, query_string = self.path.split('?', 1)
params = urllib.parse.parse_qs(query_string)
# params = {identifiant: ['valeur'], identifiant2: ['valeur2']}
html = html + params['identifiant'][0]
self.wfile.write(bytes(html, 'UTF-8'))
s = http.server.HTTPServer(("localhost", 8000), TestHandler)
print("Starting server. Ctrl+C to quit.")
s.serve_forever()