Flask vs django | easy expert comparison

Both Flask and Django are:

What is the difference Flask vs Django? TL;DR:

Github stars

Django:

Django github stars

Flask:

Flask github stars

Django Internal ORM

1. Define the model in models.py with e.g.

class Person(models.Model):
    name = models.CharField(max_length=30)
    age = models.IntegerField()

2. Run python manage.py makemigrations

3. Run python manage.py migrate

That is all! It will generate CREATE TABLE SQL statement and execute it under the hood to synchronize your models to database.

Then just do:

p = Person(name="Alex Kotli", age=28)
p.save()

And Djangos ORM will perform INSERT SQL query under the hood. If you will write:

Person.objects.filter(age__gt=18)

And it will do SELECT SQL which will return return an iterable with all persons with age grater then 18.

Flask vs Django ORM

Flask doesn't has ORM.

You can pip install side-vendor ORM called SQLAlchemey, and then connect it by imports/flask-plugins. But SQLA itself does not has a migrations, so you will then need an Alembic for migrations, and then you will need to configure both (several files but it takes time anyway)

Django admin area

Create boilerplate app, run python manage.py createsuperuser and then log in to http://127.0.0.1:8080/admin/:

Django admin area look

It already allows us to manage users/roles/permissions and could be customized for any new model! Flask doesn't has it.

What to choose in flask vs django?

Make your choice by considering one by one all pros and cones.

Django benefits, Flask disadvantages

Flask pros, Django cones

#python #django #flask
menu 14
Ivan Borshchov profile picture
Oct 22, 2020
by Ivan Borshchov

Best related

Other by Ivan Borshchov