12345678910111213141516171819202122232425262728 |
- from http import HTTPStatus
- from pathlib import Path
-
- from roll import Roll
- from roll.extensions import simple_server, static
-
- app = Roll()
- static(app)
-
-
- @app.route("/")
- async def home(request, response):
- response.headers["Content-Type"] = "text/html; charset=utf-8"
- response.body = open("index.html").read()
-
-
- @app.route("/upload_images", methods=["POST"])
- async def upload_images(request, response):
- images = request.files.list("images")
- for image in images:
- filepath = Path("uploaded_images") / image.filename
- filepath.write_bytes(image.read())
- response.status = HTTPStatus.FOUND
- response.headers["Location"] = "/"
-
-
- if __name__ == "__main__":
- simple_server(app)
|