Skip to content

Instantly share code, notes, and snippets.

@kracekumar
Created November 6, 2014 19:46
Show Gist options
  • Save kracekumar/c02a60744d5cf28044f8 to your computer and use it in GitHub Desktop.
Save kracekumar/c02a60744d5cf28044f8 to your computer and use it in GitHub Desktop.

Flask Vs Django


Who am i ?


Introduction

  • 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.

Today's discussion

  • Authentication
  • Internal/External service
  • Middleware
  • Beginner Friendly
  • Third party packages
  • Migrations/Command line tools
  • Testing
  • Misc
  • Final Words

Authentication

  • 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 ?

Internal/External Service

  • Django comes with lot of good security practices. Very good for public facing sites.
  • CSRF Token and Single Page Application.
  • Internal services don't need any security like CSRF Token.

Middleware

  • MIDDLEWARE_CLASSES in settings.py.
  • Django has middleware, every request/response goes through middleware.
  • Quite useful like logging API requests, tracking source etc ...
  • TEMPLATE_CONTEXT_PROCESSORS

Beginner Friendly

  • 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 encourages classes and functions.
  • Django's structure of project and app is standard across all Django project.

Third Party packages

  • Django has vast majority of well maintained third party apps.
  • Most of flask third party modules are broken and aren't well maintained.

Migration

  • Django 1.7 has in built migration tool (SQL only) and south.
  • SQLAlchemy has alembic for migration, flask-alembic isn't well maintained.

Management Commands

  • Django management commands are bliss to work.
  • Flask doesn't come with management commands, Flask-Script isn't great.
  • click cli library is popular.

Testing

  • Django comes with lot of Testing utilities like requestfactory, TestCase, LiveServerTestCase.
  • Third party modules like py.test-django, factoryboy .
  • Flask-testing, pytest-flask.

Misc

  • 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.

Final Word

  • Depending on purpose of web app choose the framework.
  • Flask is light weight and Django is full fledged framework.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment