No matter if you’re a beginner or Professional web developer, use Django Python web framework for your web project otherwise you’ll end up building and assembling a Django all together and you will learn that in a hard way.
Well that’s not completely true, if you’re sure that your project will never ever requires things that Django offers all together, then feel free to use something lightweight.
Many developers either beginners or advanced ones, struggle to pick up a right framework to work with. Some like the simplicity of Flask that gives them a lot of freedom so they can choose what so ever they want to.
That’s the problem right there, you have to choose, decide, maintain, glue and assemble tons of libraries to get your project working and keep doing this in as long as your application exists.
In this article I’m going to set Flask as a small lightweight framework against heavy unchained Django and talk through the example by comparing them for the scenario.
Now, creating a Blog in Web Frameworks in like a Hello World program, this is how we compare them most of the time without going into wild details.
Let’s see how to build a Blog application, a Blog web application usually has:
- Admin panel
- Authentication (Sessions, Cookies, Password Encryption, Login, Logout, etc…)
- Atom or RSS Feed
- Static Pages
- Form handling
- Template Engine
- Database (I love an ORM feature)
- Unit Testing
Those are the basic of many kind of web applications.
Flask doesn’t have anything to do with your Database, has no idea what a database is, it comes with a nice way of URL routing to your views/controllers and return the HTTP response which can contain a HTML template with Jinja as the engine. That’s it.
The rest of the cycle is on the developer.
Here’s what you need to start a simple Blog web application. The below is a list of things you need to assemble to get up and running:
- A database extension so you can write and define your User and Entry model.
- You may want to add another thing called ORM to make your life easier.
- If you don’t need to get dirty along the way, think about a database migration tool as well, so you won’t end up writing raw SQL to alter database tables.
- Authentication ext, flask has bunch of good ones. Take one that works with your database layer as well and has good sense of sessions and cookies handling.
- Your database layer would be good to have some pagination helpers as well, if not, no worries you can always write it yourself and do the optimizations and keep it sane with your database layer of choice.
- Sitemap.xml generation, you wanna be indexed in search engines right ?
- RSS or Atom Feed. It’s a Blog app, what’s the point if you don’t have one.
- Static/Flat pages. You should be able change them from your admin panel.
- Oh, you need an Admin panel.
- Your admin panel should work pretty well with all of the extensions or important parts of your application, such as database layer, Authentication, Static/Pages Pages.
- Forms, Forms, Forms! Form plays a big part in web, find a really good and flexible extension to work with.
- Searching is another important layer, would be great to have a simple Full Text Support for you blog, otherwise a simple one would do as well, but be careful to not create a dummy or useless search functionality, otherwise it would damage rather than be useful.
- Commenting, either find an extension or in many cases write your own.
- Unit Testing is really important, you might roll your own or find a great Flask ext to get it working with all of the above components nicely or try it make it in that way.
Again, please note that all the extensions you find in many cases need to work together nicely and you to have assemble them in that way, otherwise bad things might happen and you don’t want to witness such things. Remember, you can use your time to add more features and do other awesome things in your life rather than doing tons of time consuming work that could be handled much efficiently with other tools.
Now, let’s see how we can make this happens with Django.
You only need Django, that’s it, have a nice day.
Yes, move on, nothing left to do.
Plug in & Play
Both Flask and Django have nice ready made Blog web applications by the community in a very good shape. Django has Zinnia and Flask has Flask-Blogging. (Zinnia is much mature and feature complete.)
In this post I tried to show how one would implement such simple and basic thing.
It’s not about Django vs Flask or which one is the winner. Tools get built for a purpose and in many cases tools don’t wanna replace each other and they shouldn’t be looked at in that way.
Any web framework has its own area of work and capabilities, you as the developer or designer of the system should wisely decide to choose the right tool for the job.
Flask is minimal, you can create big projects with it for sure, but you realy need to glue tons of other tiny applications together, this means more maintenance and work. More work, more work and more work. You have to find the good ones, or solid ones. Each part is developed separately. If any of the part breaks other parts might start bleeding as well. If any of the third party library got abandoned or a certain bug fix is not released, then you have to deal with the issue.
This issue is there if you pick the wrong tool for the job and build bloking blocks upon each other.
Django on other hand has most of the things you need for many kind of web applications and covers them very well.
If your project is a small one page app that doesn’t need much complexity, for sure Flask rocks here. I use Flask when I have tiny and small web application that have only one tiny purpose to serve and done. On the other hand Django is my choice when complexity is higher, database is important, forms are required, admin panel is a must and integrity between my application parts has to be solid as possible. Not only with my application but other third party applications follow the same rule in Django ecosystem.
Beginners and Advanced Developers
In many cases Beginners start with micro-frameworks when others have recommended them such thing. Mainly because it’s simple to get starting with or easier to understand the “Quick Start” page of their documentation.
If a beginner wants to build a simple blogging web application, choosing a micro-framework would be a huge mistake due to above reasons that I mentioned. It adds tons of complicated processes for them, confusion after confusion and in many cases people would give up and look somewhere else. They spend a lot of times while gluing things together. Some people like to say this will make them understand more and help them to finf out what’s under the hood and how things work, I don’t think so. It usually makes them get tired and hate the whole thing.
Advanced Developers should find out more what the beginners are trying to build and then suggest them the right tools.
Use the right tool for the job.
Choose Django if:
- It makes your development faster and your life easier.
- Need database, forms, authentication, templating, etc.
- Awesome Admin panel.
- Great REST API framework.
- Your database scheme changes once a while or frequently.
- Lots of things are in the project.
- The project will need more stuff and needs to be extended fast.
- Unit testing out of the box with tons of extra sugar.
- Things you don’t know you’d need in future.
Go with Flask or any other micro-frameworks if:
- You don’t need what Django offers.
- That’s it.
Otherwise, you’ll end up building a Django.
Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!