- @Kracekumar
- Have used both Flask and Django.
- Django is a web framework with batteries included like
ORM, Templating language, Authentication, Authorization, Migration
etc ... - Flask is a micro framework which comes with
routing and templating engine
.
- Authentication
- Internal/External service
- Middleware
- Beginner Friendly
- Third party packages
- Migrations/Command line tools
- Testing
- Misc
- Final Words
django.contrib.auth
is django app which takes care of authentication.User, Group, Permission
model, decorators, login and logout signals etc ...- SQL backend and possible to use RemoteBackend.
django.http.HttpRequest.META['REMOTE_USER]
- Flask has no auth backend, third party modules like
Flask-Principal
. - Which is good ?
- Django comes with lot of good security practices. Very good for public facing sites.
CSRF Token
andSingle Page Application
.- Internal services don't need any security like
CSRF Token
.
MIDDLEWARE_CLASSES
insettings.py
.- Django has middleware, every request/response goes through middleware.
- Quite useful like
logging API requests, tracking source
etc ... TEMPLATE_CONTEXT_PROCESSORS
- Django Regex are hard to remember and easy to do mistake.
- Flask
app.route('/articles/<int:year>/<int:month>/<int:day>/')
and - Django
(r'^articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', views)
. - Flask heavily uses
decorator
Django encouragesclasses
and functions. - Django's structure of project and app is standard across all Django project.
- Django has vast majority of well maintained third party apps.
- Most of flask third party modules are broken and aren't well maintained.
- Django 1.7 has in built migration tool (SQL only) and south.
SQLAlchemy
hasalembic
for migration,flask-alembic
isn't well maintained.
- Django management commands are bliss to work.
- Flask doesn't come with management commands,
Flask-Script
isn't great. click
cli library is popular.
- Django comes with lot of Testing utilities like
requestfactory, TestCase, LiveServerTestCase
. - Third party modules like
py.test-django, factoryboy
. Flask-testing, pytest-flask
.
- Jinja2 is faster than Django template. In future Django wants to use Jinja2 (No clear Roadmap).
SQLAlchemy
has learning curve but very well designed.Django REST Framework
is well maintained in Python REST library.- Flask Admin is poorly maintained.
- Depending on purpose of web app choose the framework.
- Flask is light weight and Django is full fledged framework.