How to execute python script on the BaseHTTPSERVER created by python?

前端 未结 3 391
抹茶落季
抹茶落季 2020-12-16 08:43

I have simply created a python server with :

python -m SimpleHTTPServer

I had a .htaccess (I don\'t know if it is usefull with python serve

3条回答
  •  心在旅途
    2020-12-16 09:23

    Have you tried using Flask? It's a lightweight server library that makes this really easy.

    from flask import Flask
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def hello_world():
        return 'Hello World'
    
    
    if __name__ == '__main__':
        app.run(debug=True)
    

    The return value, in this case Hello World, is rendered has HTML. You can also use HTML template files for more complex pages.

    Here's a good, short, youtube tutorial that explains it better.

提交回复
热议问题