Django vs other Python web frameworks?

后端 未结 13 2202
抹茶落季
抹茶落季 2020-12-02 05:35

I\'ve pretty much tried every Python web framework that exists, and it took me a long time to realize there wasn\'t a silver bullet framework, each had its own advantages an

13条回答
  •  攒了一身酷
    2020-12-02 06:41

    Learn WSGI

    WSGI is absurdly simple.. It's basically a function that looks like..

    def application(environ, start_response) pass
    

    The function is called when an HTTP request is received. environ contains various data (like the request URI etc etc), start_response is a callable function, used to set headers.

    The returned value is the body of the website.

    def application(environ, start_response): start_response("200 OK", []) return "..."

    That's all there is to it, really.. It's not a framework, but more a protocol for web-frameworks to use..

    For creating sites, using WSGI is not the "right way" - using existing frameworks is.. but, if you are writing a Python web-framework then using WSGI is absolutely the right way..

    Which framework you use (CherryPy, Django, TurboGears etc) is basically personal preference.. Play around in each, see which you like the most, then use it.. There is a StackOverflow question (with a great answer) about this, "Recommendation for straight-forward python frameworks"

提交回复
热议问题