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.

server.py 710B

12345678910111213141516171819202122232425262728
  1. from http import HTTPStatus
  2. from pathlib import Path
  3. from roll import Roll
  4. from roll.extensions import simple_server, static
  5. app = Roll()
  6. static(app)
  7. @app.route("/")
  8. async def home(request, response):
  9. response.headers["Content-Type"] = "text/html; charset=utf-8"
  10. response.body = open("index.html").read()
  11. @app.route("/upload_images", methods=["POST"])
  12. async def upload_images(request, response):
  13. images = request.files.list("images")
  14. for image in images:
  15. filepath = Path("uploaded_images") / image.filename
  16. filepath.write_bytes(image.read())
  17. response.status = HTTPStatus.FOUND
  18. response.headers["Location"] = "/"
  19. if __name__ == "__main__":
  20. simple_server(app)