Flask 与 Django 的简单对比
So I was going to do a Flask tutorial this week after learning it in a week, but I decided to do a comparison with Flask and Django since I've had hands-on-experience with both python web frameworks. The reason is so that I can help you choose which framework to learn as learning a framework can be very time consuming —- but very fun of course!
CAUTION: I only spent a week with Flask whereas I've used Django for the past 3 years. Take this with a grain of salt 😅
Let's start with similarities.
1) Flask and Django are both python web frameworks.
They enable you to create web applications using python for backend logic and html and css as front, or whatever front-end framework you'd prefer.
2) Can use ORM or object-relational-mapping.
This basically means, you can use SQLITE, MYSQL, PostgreSQL, and other databases that utilizes ORM.
-Django by default uses ORM.\
-Flask does not come with ORM capabilities by default. You need to manually add it if you want.
-Django uses a template engine similar to Jinja (actually Jinja was inspired by Django's own templating system)
Small comment: Django doesn’t use Jinja, but it’s own templating engine. They look similar because, as Jinja’s website says, “It is inspired by Django's templating system.”
-Flask uses Jinja as its template engine.
Jinja is basically like python for html (python + html = Jinja) that enables you to add logic to your html such us if/else, for-loops, and extension of templates which I really really love!
There are many more similarities between Flask and Django, but for me those are three the main ones.
The differences are quite big when you put Flask and Django side by side.
With Flask you get incredible flexibility.
You create the app.py (which is like the main logic for your app), the models.py (which is where you store your models that creates the tables for your database), the templating and etc. You have ABSOLUTE control on how you want to build the structure for you app.
With Django, it's all built for you!
The settings.py (which is like the config file for your app) the models.py, the urls.py (which is where all the routings are stored), the templating, etc.
Which is why Django's tag is, "The web framework for perfectionist with a deadline." Because everything is built in, you don't need to bother yourself with creating the files and thinking about how you should structure your app. It's all ready for you and you can immediately get started with building your app.
Flask and Django both have their strengths and weaknesses.\
Each one has their own uses and purposes.
If you're making an app that's simple that doesn't anything too complex, then Flask is the way to go.
But if you're a beginner and want to get into web development with python, I'd suggest you start with Flask. The things you learn in Flask can be applied to Django. It's just easier with Flask.
我们的翻译工作遵照 CC 协议，如果我们的工作有侵犯到您的权益，请及时联系我们。