Django vs other Python web frameworks?

后端 未结 13 2165
抹茶落季
抹茶落季 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:31

    the religious debates between the Django and WSGI camps

    It would seem as though you're a tad bit confused about what WSGI is and what Django is. Saying that Django and WSGI are competing is a bit like saying that C and SQL are competing: you're comparing apples and oranges.

    Django is a framework, WSGI is a protocol (which is supported by Django) for how the server interacts with the framework. Most importantly, learning to use WSGI directly is a bit like learning assembly. It's a great learning experience, but it's not really something you should do for production code (nor was it intended to be).

    At any rate, my advice is to figure it out for yourself. Most frameworks have a "make a wiki/blog/poll in an hour" type exercise. Spend a little time with each one and figure out which one you like best. After all, how can you decide between different frameworks if you're not willing to try them out?

    0 讨论(0)
  • 2020-12-02 06:33

    I would suggest for TurboGears 2. They have done a fantastic job of integrating best of Python world.

    WSGI: Assuming you are developing moderately complex projects/ business solutions in TG2 or some other framework say Grok. Even though these frameworks supports WSGI does that mean one who is using these frameworks have to learn WSGI? In most cases answer is No. I mean it's good have this knowledge no doubt.

    WSGI knowledge is probably is more useful in cases like

    • you want to use some middleware or some other component which is not provided as part of the standard stack for eg. Authkit with TG or Grok without ZODB.
    • you are doing some integration.

    CherryPy is good but think of handling your database commits/rollbacks at the end of transactions, exposing json, validations in such cases TG, Django like frameworks do it all for you.

    0 讨论(0)
  • 2020-12-02 06:34

    Your question seems to be "is it worth learning WSGI and doing everything yourself," or using a "full stack framework that does everything for you."

    I'd say that's a false dichotomy and there's an obvious third way. TurboGears 2 tries to provide a smooth path from a "do everything for you" style framework up to an understanding of WSGI middleware, and an ability to customize almost every aspect of the framework to suit your application's needs.

    We may not be successful in every place at every level, but particularly if you've already got some TurboGears 1 experience I think the TG2 learning curve will be very, very easy at first and you'll have the ability to go deeper exactly when you need it.

    To address your particular issues:

    • We provide an authorization system out of the box that matches the one you're used to from TG1.
    • We provide an out of the box "django admin" like interface called the tgext.admin, which works great with dojo to make a fancy spreadsheet like interface the default.

    I'd also like to address a couple of the other options that are out there and talk a little bit about the benifits.

    • CherryPy. I think CherryPy is a great webserver and a nice minimalistic web-framework. It's not based on WSGI internally but has good WSGI support although it will not provide you with the "full stack" experience. But for custom setups that need to be both fast and aren't particularly suited to the defaults provided by Django or TurboGears, it's a great solution.

    • Django. I think Django is a very nice, tigtly integrated system for developing websites. If your application and style of working fits well within it's standard setup it can be fantastic. If however you need to tune your DB usage, replace the template language, use a different user authorization model or otherwise do things differently you may very likely find yourself fighting the framework.

    • Pylons Pylons like CherryPy is a great minimalistic web-framework. Unlike CherryPy it's WSGI enabled through the whole system and provides some sane defaults like SQLAlchemy and Mako that can help you scale well. The new official docs are of much better quality than the old wiki docs which are what you seem to have looked at.

    0 讨论(0)
  • 2020-12-02 06:39

    Have you checked out web2py? After recently evaluating many Python web frameworks recently I've decided to adopt this one. Also check out Google App Engine if you haven't already.

    0 讨论(0)
  • 2020-12-02 06:39

    Web2py is the secret sauce here. Don't miss checking it out.

    0 讨论(0)
  • 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"

    0 讨论(0)
提交回复
热议问题