Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Form server
<!DOCTYPE html>
<form action="/" method="post" enctype="multipart/form-data">
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname"><br>
<input type="file" name="file"><br>
<input type="submit">
from aiohttp import web
async def render_form(request):
with open('form-data.html') as f:
return web.Response(, content_type='text/html')
async def print_form(request):
text = await request.text()
headers = "\n".join(f"{name}: {val}" for name, val in request.headers.items())
body = f"{headers}\r\n------------------------\r\n{text}"
return web.Response(text=body, content_type='text/plain')
async def init():
app = web.Application()
app.add_routes([web.get('/', render_form)])
app.add_routes(['/', print_form)])
return app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.