Serve a form with the given enctype, and display back the submitted value.
(request: Request)
| 40 | |
| 41 | @server.route("/form", [GET, POST]) |
| 42 | def form(request: Request): |
| 43 | """ |
| 44 | Serve a form with the given enctype, and display back the submitted value. |
| 45 | """ |
| 46 | enctype = request.query_params.get("enctype", "text/plain") |
| 47 | |
| 48 | if request.method == POST: |
| 49 | posted_value = request.form_data.get("something") |
| 50 | |
| 51 | return Response( |
| 52 | request, |
| 53 | FORM_HTML_TEMPLATE.format( |
| 54 | enctype=enctype, |
| 55 | submitted_value=( |
| 56 | f"<h3>Enctype: {enctype}</h3>\n<h3>Submitted form value: {posted_value}</h3>" |
| 57 | if request.method == POST |
| 58 | else "" |
| 59 | ), |
| 60 | ), |
| 61 | content_type="text/html", |
| 62 | ) |
| 63 | |
| 64 | |
| 65 | server.serve_forever(str(wifi.radio.ipv4_address)) |