Live data from Hacker News

A Beginner’s Introduction to Python Web Frameworks (2018)

stxnext.com

151–160 of 168 posts

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#151

I started Python programming 8 or 9 years ago and went from bottle to flask to Falcon to Django to Sanic. Django is incredible - I wish I'd started with it. It's truly the most useful framework I've ever used - a real workhorse for building applications. Flask and bottle are minimalist and get the job done for focused tasks - for example I hacked together various web examples into an mjpeg server recently used Flask…

Veering a bit off topic here, but I somewhat recently used MJPEG for a "live preview" type of application and found support on the browser side to cause no end of frustration. Details escape me now, but some browsers could never be made to stop streaming without closing the tab, certain versions of Chrome didn't work at all.

It felt great to finally figure out the correct HTTP header incantations to get a working-ish solution with MJPEG... but if I had time to revisit it I would have tried instead encapsulating JPEG frames in WebSocket messages and blitting them to a canvas with JS.

MJPEG seems to be firmly in legacy territory and while browser vendors have to keep supporting it for IP cams, it's probably going to keep getting hit with the regression stick. Meanwhile WebRTC is notionally the correct replacement technology but the complexity is high and support is still hit or miss.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#152

Earlier quoted context omitted.

Flask, and only Flask.

That seems like a rather extreme statement.

Like any answer here, it's my opinion. If it were not extreme, then it would be not a very strong opinion or worth considering.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#153

Earlier quoted context omitted.

Django brings a lot of concepts with it. It may be simpler to start teaching with Flask and build up from there until the need for something like Django becomes obvious.

Right. With Flask, I can simply get to the point where I'm rendering templates, styling with CSS, adding assets and populating template variables with data from simple (or complex) functions I've written. You can take care of a lot with just that.

Eventually, when the application reaches production, you'll have cobbled together a unique subset of Django.

That's the downside of Flask.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#154
post #38
post #35

I was forced to encounter Web2Py in an open-source project several years ago. It was awful. Besides the fact that it's stuck in Python 2 (seriously, even today?), it had a lot of bizarre design decisions. For instance, it loaded controllers by concatenating files in a directory - alphabetically. I know Python's import system can confuse some folks, but surely there was a better way. The whole thing left a very sour t…

I LOVE Web2py! I use it for pretty much all of my projects. It is the only Python framework that is super easy to use, has enough "batteries included" but not too much, super simple and super powerful templating, decent migrations, simple data access layer not complicated ORM, no import hell, implicit routing. Developer has a new effort underway that is a little more "pythonic": https://github.com/web2py/py4web

> no import hell

What's the problem with import?

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#155

Earlier quoted context omitted.

> Also, you don't get much by switching Django templates to Jinja. Well, you gain a lot of performance - as much as 10x depending on the complexity of your template. Also, Jinja is a lot less crippled than Django Templates (for example, you can't call a function/method with parameters in Django Templates).

Bear in mind "crippled" was a deliberate design choice. Templates have a habit of taking over business logic and before you know it you've reinvented old school PHP.

It is a design decision from a time where the general belief was that template designers played in a lower league compared to "real" software developers.

It is 2019 and personally I see no reason to think professional template designers will shoot themselves in the foot if we give them too much power. We are all consenting adults...

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#156

Earlier quoted context omitted.

Bear in mind "crippled" was a deliberate design choice. Templates have a habit of taking over business logic and before you know it you've reinvented old school PHP.

It is a design decision from a time where the general belief was that template designers played in a lower league compared to "real" software developers. It is 2019 and personally I see no reason to think professional template designers will shoot themselves in the foot if we give them too much power. We are all consenting adults...

A stated reason is:

https://django-best-practices.readthedocs.io/en/latest/appli...

A common pattern in MVC-style programming is to build thick/fat models and thin controllers. For Django this translates to building models with lots of small methods attached to them and views which use those methods to keep their logic as minimal as possible. There are lots of benefits to this approach.

DRY: Rather than repeating the same logic in multiple views, it is defined once on the model.

Testable: Breaking up logic into small methods on the model makes your code easier to unit test.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#157

This is a great resource, and there are some neat inclusions like Falcon, but I find the main trouble when building python web apps is deployment. I always feel like I've duct-taped my carefully written app to the web-server.

You can very easily deploy WSGI-compatible apps to AWS Lambda in seconds with the open-source library Zappa (https://github.com/Miserlou/Zappa). Zero server maintenance and zero cost if nobody is using your apps (I put up personal apps all the time with this paradigm, it's great). I love it so much I wrote a book about it: https://compellingpython.com/

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#158
post #148

This is a short list I have compiled a few months ago, FWIW: New kids on the block: - Starlette https://www.starlette.io - Vibora https://vibora.io - Xweb https://github.com/gaojiuli/xweb - Storm https://github.com/jiajunhuang/storm - Responder http://python-responder.org - Quart https://pgjones.gitlab.io/quart/ - Sanic https://sanic.readthedocs.io - Bocadillo https://bocadilloproject.github.io/ - Japronto https://gi…

I don't think Falcon is "old guard". It got stable just about 3 years ago.

Welcome to Hacker News, where anything older than two weeks is utterly obsolete and unusable, unless it’s LISP.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#159

Earlier quoted context omitted.

I traditionally like using the libraries not the Flask integrations (as in your sqlalchemy example) however I do find myself using Flask Admin and Flask-WTForms, since while they do have downsides and you have to commit to using them, they do a lot for you. I haven't checked out CherryPy, I should next hobby project. Gunicorn is awesome, uWSGI is also good and feels more "production" to me.

My problem with those additional projects are that I am dependent on one another layer of abstraction and not sure if the team is able to continue to develop it if core developers abandon it. Thats the reason I prefer using libraries, which if not supported can be supported by my team or replaced if necessary. We use Flask mostly for REST API, so flask-admin and WTForms do not add that much value as all those are don…

For my apps I'm not worried about abandonment. They are internal applications generally with no access from the web.

Also the code is solid enough where I feel I could maintain it if I needed to, but most likely it would get picked up by someone else.

Re: A Beginner’s Introduction to Python Web Frameworks (2018)

#160
post #12

I started working with Python around 2013 and I still consider Django the best framework to use. Yes Flask you can pick what you want to use but I have found the supporting libraries to be a bit outdated. Everytime I have used it I feel like I am just gluing together a lot of different pieces and it becomes messy. Django is constantly updated and I have little to no worries about security issues. Edit: And I have bee…

As with Rails, my take is that if you need to make a web app, use the big framework. The pieces you don't use don't cost much in terms of performance or maintainability, but the inverse is true otherwise: piecing together your own Django with a lighter weight framework adds a maintenance overhead that you wouldn't have with a batteries-included framework. I use Flask for simple APIs and microservices. If I'm writing…

Thanks for pointing that out. I agree 100%. Simple APIs and microservices benefit from flask. The moment I need anything like auth though I just jump straight to Django. I don't want to think about it.
Post reply on HN