klein-mvc

Python Klein - Non Blocking API

百般思念 提交于 2020-02-05 03:28:10
问题 Need help with Klein API for Non-blocking. This is a simple test app: # -*- coding: utf-8 -*- import datetime import json import time from klein import Klein app = Klein() async def delay(seconds): """Set some delay for test""" time.sleep(seconds) return "Works" @app.route('/', branch=True) async def main(request): some_data = await delay(5) return json.dumps([{ "status": "200", "time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "data": some_data }]) app.run("localhost", 8080)

How do I run Klein with twisted?

断了今生、忘了曾经 提交于 2020-01-06 03:21:52
问题 I'm trying to run klein with twisted, so I can run twisted scripts on different paths (exp: example.com/example1 , example.com/example2 ). So I made a simple script: from klein import run, route, Klein from twisted.internet import reactor from twisted.web import proxy, server from twisted.python import log @route('/example') def home(request): site = server.Site(proxy.ReverseProxyResource('www.example.com', 80, b'')) reactor.listenTCP(80, site) reactor.run() run("My_IP_Address", 80) But

How to receive uploaded file with Klein like Flask in python

余生长醉 提交于 2019-12-23 08:51:15
问题 When setting up a Flask server, we can try to receive the file user uploaded by imagefile = flask.request.files['imagefile'] filename_ = str(datetime.datetime.now()).replace(' ', '_') + \ werkzeug.secure_filename(imagefile.filename) filename = os.path.join(UPLOAD_FOLDER, filename_) imagefile.save(filename) logging.info('Saving to %s.', filename) image = exifutil.open_oriented_im(filename) When I am looking at the Klein documentation, I've seen http://klein.readthedocs.io/en/latest/examples