| Which is why I put all the logic into a single place. Extra methods on Django Models? Nope. A function in my business logic package which takes a model instance as parameter? Yes. Models should only contain data. Huge views that do more than one thing? Nope. A function, or a class, in my business logic package which takes the request data (POST form, GET query string) and returns the data to feed to the template and/or the "state" needed to decide which template to render? Yes. Views should be small. Also, split your templates, don't be afraid of `{% include %}` (which works well with HTMX as well). This methodology also have another huge advantage. If you need to walk away from Django, you can. Your business logic won't change that much (there are not many difference between a Django Model instance and an SQLAlchemy model instance, or even a MongoEngine model instance). Your business logic knows nothing of HTTP or serialization. Django, and Flask or any other framework are just the glue between the WSGI/ASGI and your business code. If your code is async but your web framework isn't, you can still put a `asyncio.run` or `trio.run` inside your view, and you won't have to change a thing once you switch to an async web framework. Basically, I use Django for: - the ORM
- the Forms
- the routing with urls.py
- the settings management
- the templating engine
- the builtin User system
- the builtin admin website
- the vast ecosystem (django-anymail, django-tailwind, django-money, django-flags, django-social-auth, ...)
What I dislike about Flask is: - routing is tied up to the views (via a decorator)
- the request object is a global singleton instead of a function parameter
- no builtin admin website (this is just so useful to get things going at the beginning)
- there is a lot of boilerplate to make the different extensions work together where django is just about adding a string to INSTALLED_APPS
|
btw, didn't django add routing decorators too ? I always prefered it to split file because .. it's a small amount of information that needs to be tracked separately mentally if in urls.py .. plus inclusion/sub-routes feel confusing (but that may only be me)