Home > Technical & Creative Skills > Programming, Servers & Scripts

Question For The Python Experts: Django or Flask (3)


03-30-2022 08:55 PM #1 twinaxe (Senior Moderator)
Question For The Python Experts: Django or Flask

After a little break I want to continue working on my Python campaign automation scripts and now I think about best options to implement a frontend interface.

As framework for the web app I want to use either Django or Flask but the decision is hard so it would be great to get some input

I don´t have a concrete idea yet how exactly the app shall be but a rough plan is to have a navigation bar on the left side of the screen and a dashboard to display stuff or enter data on the right side.

In the navigation bar there will probably be blocks for the different tasks/functions, these could be things like

- Show campaign stats
- Show charts/graphs about best/worst segments, combinations or whatever
- Control interface to define optimization rules and attach the rules to campaigns
- Notification and log of activities
- Control interface to set parameters for automated campaign creation (select trafficsources, set ad format, CPC/CPM or CPA, set bid, budget and such stuff)
- Show Traffic Companies IVR API stats together with predicitons of good working targetings

I don´t know if I will implement all of these things, it´s just that you can get an idea what I roughly want to do.

I found Appseed, they offer some very nice dashboards that are available for Django as well as for Flask.

For example there´s Datta Able for Django and for Flask, they both look exactly the same.
Then there´s their Volt dashboard for Django and for Flask, both look exactly the same.
Their Soft UI dashboard for Django and for Flask as well, both look exactly the same.

These examples already show that all the things I ant to do can be done with either Django or Flask but I am not sure what the better choice is.

From what I read an advantage of Django is that it has already more or less everything that you need to build all kind of websites implemented whereas in Flask you only have a pretty basic framework and you need to implement all kinds of more advanced features yourself.

For example things like database management, admin backend, login functions (with secure authentication) are already implemented in Django.

There I see an advantage for Django but the disadvantage there is that I always have to install the full package, even when I need only 5% of the included functions.
This is also something that I ususally don´t like at all, I prefer to learn and use only exact the things that I need for a project so that I don´t have to mess around with things that I don´t need anyway.

In Flask all such things are not included by default so I have to implement and connect everything myself.

At first it sounds like a disadvantage but on the other hand I don´t have to install any unnecessary packages and you can install only the things that are needed for the project.

This gives much more flexibility but maybe also more room for (user made) errors.

Another point is what frameworks makes it easier to add new functionality to a project.

Related to the examples above, let´s say I want to add a new block with new functions, would it be easier in Django or Flask to add all the new stuff to the frontend and connect the new functions from the backend code?

Then Django has a rather fixed structure how web apps are build there, in Flask you can/have to do it very flexible.

I am not sure what approach I prefer.
A fixed structure has the advantage that you don´t have to think that much about how to structure your project because you have to depend on Djangos structure anyway.
It will probably also be helpful when you create multiple projects, when you always have the same structure and get used to it it´s probably way easier and faster then to get something done.

A flexible structure however gives you the freedom to build your projects exactly the way you want and not the way the framework allows you to do.

I´m really torn between these two frameworks because both of them seem to be the better choice as well as the worse choice at the same time.

On one hand I already decided to use Django because my mind says it seems to be the more mature and more rational choice.
On the other hand I already decided to use Flask because my heart says it seems to be more fun and more exciting and together with it´s flexibility it would probably be the much better match for my personality and workstyle.

Would be great if the ones of you who know both frameworks could give some input that hopefully helps with the decision.

Edit: Now I have read a bit more and see that many people talk about FastAPI and it also sounds pretty interesting.

It even looks like FastAPI could be a better alternative to Flask, this doesn´t make the decision easier but good to see that there are other great options as well.

From what I see FastAPI is faster than Flask and also a bit easier to code.

In the newest PyCharm version there is also FastAPI integrated, will definitely check it out.


04-01-2022 11:39 PM #2 jeremie (Moderator)

Flask is a microframework that will be best suited for your case as it looks like pretty simple requests + stats display. Django allows to automate more complex stuff, but you don't seem to need them. I personally use none of them. I use AWS API gateway or CloudFront + AWS Lambda functions in Python / Node.js for the backend, that output JSON if data is needed on the front-end.

Yet, it seems that you want a framework to render your front-end pages. If you can not decide which Python framework, note that you don't need to use one. You can build your interface using a JS front-end framework that will receive JSON data from the backend and that is specialized in drawing graphs, such as D3 (https://d3js.org/) or Chart.JS (https://www.chartjs.org/) for something a bit more simple. Or you can also use a simple Google Sheets with a Google Apps Script that calls your backend and fill the cells of the sheet with the data you want.


By doing so:
- you keep a clean back-end that is only focused on treating data and taking decisions (campaign / placement bid or pause, bot detection...) and exporting data into a JSON format that is readable by your specialized front-end.
- once you have configure your back-end endpoint to query and output data from your database, you can play with your data by changing your front-end code without messing with your backend code, which is useful if the back-end is also used live to take decisions on your campaigns.

In that case, no back-end framework or Flask would be the best option for your back-end.

But now, you have an other dilemma : which front-end framework to choose...


04-02-2022 01:52 AM #3 twinaxe (Senior Moderator)

I already have a clearer picture now

The last days I was researching and reading alot because I couldn't decide at all.

And just as you said, there's not only the backend so that I also have to decide what to use for the frontend.

But let me first tell my thoughts about the backend.

I am 100% confident that using Django would be the more reasonable decision.
Django already has everything I would need for the project, it's mature, runs stable and is reliable.

Another big advantage is that Django is maintained by the Django Software Foundation.
This means the whole development is basically in one hand and all components in Django are well-matched and you can be sure that they work good together.

With Flask you have to use several external libraries that are maintained by different individuals and you can't be that confident that they also work together that good.

Nonetheless I decided against Django.

As I said in the previous post, Flask is probably better match for me because there I can do the things how I want to do it and don't have to do it how Django allows me to

I have read two sentences that describe pretty good why I (among other things) decided against Django.

The first sentence was: "With Flask you build your framework around your scripts, with Django you build your scripts around the framework."

This describes the situation pretty good and I prefer to be more flexible with my scripts so that I can make them exactly the way I want them to be and because of the looser structure of the framework I can adjust the framework to fit my scripts.

With Django I would have the do it the Django way and the hands are tied much more so that I wouldn't have that much room for creativity and I can imagine that I could miss some opportunities when I can't do the things the way I want to.

Sure, there will probably be workarounds for many things but I want to be my own boss with own decisions

The second sentence that I have read was: "With Flask you learn to code Python, with Django you learn to code Django".

This also got me thinking.
Maybe it wouldn't be an issue when I am 100% confident that I will use Django alot so that it's worth it to really learn it.
Django is so large and extensive that you just have to really learn it when you want to get most out of it.
It's basically a huge ecosystem on its own with own rules and own characteristics so that I would have to learn the "Django syntax" instead of learning general coding that can be used for many more things.

But even though I decided against Django I probably also won't go with Flask.

After long back and forth I decided to try it with Fastapi for the backend and as database I will use MongoDB.

The decision about the frontend wasn't that hard, there I will try to get it done with React.

So for now the plan is to use FastAPI + MongoDB + React.

That combination should definitely be able to get the job done and if I succeed with that stack I will probably also learn enough things that can be helpful for future projects.

Will try to get first simple functions coded soon so that I can get a better idea how to connect the frontend with the backend with the database and back

I already found Axios, seems to be a good JS library for API requests and it also supports JSON very good, this could be helpful in combination with MongoDB.

So far I have absolutely no idea how to code the frontend nor the backend or how to let them communicate with each other but I am confident that I can get it to work somehow.

I let you know how it goes


Home > Technical & Creative Skills > Programming, Servers & Scripts