You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

quadrat.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import http.server
  2. import urllib.parse
  3. class EingenerHandler(http.server.BaseHTTPRequestHandler):
  4. def do_GET(self):
  5. self.send_response(200)
  6. self.end_headers()
  7. parsed = urllib.parse.urlparse(self.path)
  8. query = parsed.query
  9. query_components = urllib.parse.parse_qsl(query)
  10. query_params = list(query_components)
  11. param1, param2 = None, None
  12. response = ""
  13. if len(query_params) > 0:
  14. param1 = int(query_params[0][1])
  15. param2 = int(query_params[1][1])
  16. for i in range(param1, param2 + 1):
  17. response += "<tr><td>{}</td>\n<td>{}</td></tr>\n".format(i, i * i)
  18. message = """
  19. <html>
  20. <head>
  21. <title>Meine Aufgabe</title>
  22. <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
  23. <style>
  24. body {
  25. background-color: lightblue;
  26. }
  27. h1 {
  28. color: white;
  29. text-align: center;
  30. }
  31. p {
  32. font-family: verdana;
  33. font-size: 20px;
  34. }
  35. table, td, tr {
  36. border: 1px solid black;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <h1>Aufgabe : Quadratzahlen</h1>
  42. <table>""" + response + """
  43. </table>
  44. </body>
  45. </html>
  46. """
  47. self.wfile.write(message.encode('utf-8'))
  48. Port = 2323
  49. Handler = EingenerHandler
  50. address = ('', Port)
  51. server = http.server.HTTPServer(address, Handler)
  52. server.serve_forever()