Django vs Flask, 무엇을 선택해야 할까요!

목차



  • Introduction

  • Flask
  • Background
  • Who uses flask


  • Django
  • Background
  • Who uses Django


  • Similarities
  • Differences
  • Conclusion

  • 소개

    Hello, hope you are doing well, well, this is 2022 knocking at the door and we need to start doing things its new way it is coming along with.
    Whereas there are more than 50 frameworks of Python, there are only two of these that have continuously become the kings of the web, flask and Django at least as far as 2021.
    These two frameworks seem to be the most mature and most loved on the web by many beginners, advanced developers and companies. They give us a chance to use the world's best language for full stack development. Let's break them and we get to know which to learn and use when! Can we roll!!

    플라스크

    배경

    Flask was created by Armin Ronacher of Pocoo, an international group of Python enthusiasts formed in 2004. According to Ronacher, the idea was originally an April Fool's joke that was popular enough to make into a serious application. The name is a play on the earlier Bottle framework.
    When Ronacher and Georg Brandl created a bulletin board system written in Python, the Pocoo projects Werkzeug and Jinja were developed.

    Flask's philosophy according to this article is to let the developer take on the driver's seat and have total/full control over the application they are developing.
    This has made the framework become the no.1 choice to most of the developers that love doing things their own way.

    Flask code sample:

    from flask import Flask
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def hello():
        return 'Hello, World!'
    

    With the above code, you have a full application that outputs Hello, World in the browser running on http://localhost:5000 , amazing, right!

    플라스크를 사용하는 사람

    Well, flask being a python light weight framework, most of the companies have picked it to play a big role in building micro-services. As we have seen in the above code snippet, with just one file, you have a fully working app. Therefore, over 900 companies may not entirely be depending on flask as the primary backend framework but include it in their stack.
    This list only shows the top 10.

    1. Netflix
    2. Reddit
    3. Lyft
    4. CRED
    5. Trivago
    6. Zalando
    7. MIT
    8. Patreon
    9. ML
    10. Sendcloud
    As per this writing, Flask had 2.2k watches, 57.1k stars and 14.7k forks on github, these may have changed by the time you are reading this but you can click here for the current standings

    장고

    Django (/ˈdʒæŋɡoʊ/ JANG-goh; sometimes stylized as django) is a Python-based free and open-source web framework that follows the model–template–views (MTV) architectural pattern. It is maintained by the Django Software Foundation (DSF), an independent organization established in the US as a 501(c)(3) non-profit.

    배경

    Django was created in the fall of 2003, when the web programmers at the Lawrence Journal-World newspaper, Adrian Holovaty and Simon Willison, began using Python to build applications. Jacob Kaplan-Moss was hired early in Django's development shortly before Simon Willison's internship ended. It was released publicly under a BSD license in July 2005. This framework has been around for over 16 years atleast as per this writing! The framework was named after guitarist Django Reinhardt.

    장고를 사용하는 사람

    Well various applications/companies or even tools may not be using Django as the framework but it's counterpart framework Django Rest framework which is a derivative of the same.

    The list shows the companies currently using Django in their progressive work. The list only shows the top 10 but there are more.

    1. Disqus
    2. Instagram
    3. Bitbucket
    4. MacArthur Foundation
    5. Mozilla
    6. National Geographic
    7. Open Knowledge Foundation
    8. Pinterest
    9. Open Stack
    10. Spotify


    이 글에 따르면 Django는 github에 2.3k 시계, 62.1k 별 및 26.5k 포크를 가지고 있습니다. 이 글을 읽고 있는 시점에는 변경되었을 수 있지만 Django repo for the current stand

    유사점

    Well, no matter how they seem to be, the two frameworks share somethings in common which you can not under look. And the matter of the fact, if you are ready comfortable with one, you will find it extremely easy to move one to the next. Like the process is seamless.

    Here are the similarities you will find in both.

  • Python frameworks. Well, without knowledge of python, then you won't be able to write the two frameworks. The are highly Object oriented, and therefore all functions, classes and data structures from python itself, can be used in both.
  • Fullstack frameworks. Both are independent fullstack frameworks, that is, you will not need any other framework alongside them to develop the backend, frontend etc. They come with inbuilt template engines to handle the front-end and use python to handle the backend.
  • ORM for models. The frameworks use Object Relational Mappers to provide quick interactions with the database. Whereas Flask does not ship in with this functionality, a special tool to achieve the same has been developed called Flask-SQLAlchamey . 반면에 ORM 기능은 django에 내장되어 있으며 Django가 대부분의 다른 프레임워크를 능가하는 기능 중 하나입니다.

  • 요청-응답 동작. 두 프레임워크 모두 요청을 수신하고 일부 논리를 수행하고 올바른 응답에 매핑하는 보기와 같은 기능을 찾는 것을 놓치지 않을 것입니다. 이 응답은 새 페이지, 일부 json 또는 파일을 반환할 수 있습니다.

  • 경로/URL. 디자인은 다르지만 기능은 다르지 않습니다. 이것은 매퍼로서 프레임워크에 어떤 요청에 대해 반환할 뷰를 알려줍니다.
    6.** 세션 및 인증**. 반면 플라스크를 사용하여 세션을 자동으로 시작할 수는 없지만 세션 시작, 업데이트, 삭제 및 인증 수행을 위한 도우미 기능은 프레임워크에서 제공됩니다. 이러한 기능 중 일부는 flask의 일부 추가 라이브러리로 달성할 수 있지만 django의 외부 라이브러리에 의존하는 것은 귀하에게 달려 있습니다. 어떤 선택을 선택하든 두 가지 모두에서 기능을 쉽게 처리할 수 있습니다.

  • 내장 템플릿 엔진. 완전히 같지는 않지만 프레임워크에는 템플릿을 빌드하는 방법이 내장되어 있습니다(사용자가 보는 것). 이를 통해 루프, 조건문, 문자열 측면 등과 같은 파이썬 기능이 제공됩니다. Flask는 Jinja2를 사용하지만 django에서는 Jinja2를 사용하도록 선택할 수 있지만 이것이 기본값은 아닙니다. Django는 django 템플릿이라고 하는 자체 템플릿 엔진을 정의했으며 이는 약간의 업그레이드로 Jinja2와 매우 유사하게 작동합니다.

  • 이것들이 유일한 유사점은 아니며 끝없는 것이 확실히 더 커질 것이지만 위에서 더 많은 것을 스캔하십시오 ...
    다음으로 둘의 차이점에 대해 알아보겠습니다.

    차이점

    There will be a few distinctions between the two frameworks, and that's the reason why I had put it that switching from one to another shall really be seamless. Let's see how they differ.

    1. Architecture. Django is MVT(That is, Model-View-Template). Now do not take "View" for how other frameworks of MVC(Model-View-Controller) take it, Model-will still be Model, View will be equivalent to Controller and Template will equivalent to View in MVC. Somehow confusing right!, please read the docs to understand how django handles this feature. Django stores and names these files accordingly and most of them are provided by default. On the other hand, Flask is a modular framework, which means, one file can even contain the whole app. Whereas, the architecture is internally maintained as for django, the structure is entirely upon you.
    2. Flexibility. Django is meant for developers who want to get tasks complete in time. That's why you will find most of the features provided for by default. This may look a good thing and will actually do the right work for you, but this means you will have less freedom of updating the defaults which will require extra knowledge of the framework to update these features. On the other hand, Flask is entirely flexible, ground up. In brief, there is no convention of designing a Flask application. This also looks good for the start, but when the project starts getting complex, new members, and/or even old team may find it hard to update the code.
    3. Scalability. Flask is highly meant to develop modular applications also known as micro services in the same project. This implies that different developers can work on different small modules independent of each other but communicating together. However, django is somehow different. Django itself is considered a project, and then inside it, you set up as many applications as you feel like. This let's django handle even the most complex project with ease. Also the development convention of django while creating these apps makes it very simple for one to divide out members to work on different modules within the same project without necessarily handling them in a distributed format. Also, plugging in a new app is very seamless also and does not affect the other applications ran in the same project.
    4. Security. Whereas in django, starting from the user, and all the forms of authentications such as creating accounts, logging in, resetting and changing passwords, confirming passwords and many more are inbuilt, flask loses out on some of these features and you will end up building them from scratch or depending on third-party libraries. Features like cryptography, click-jacking, CSRF and worked upon by django by default.
    5. Learning curve. If you already know python, Flask should take at most a week to write your first application. This differs with django, most developers have confessed that understanding the file structure of the framework has become an issue, however, understanding this flow will make django equally easier. Therefore, django will require you to at least two weeks to feel comfortable working on a good project.
    6. ORM. Whereas flask depends and works well with Flask-SQLAlchamy, Django's ORM is a killer. From the process of creating models, tracking and squashing, working with more than one database, and changing from one database to the other. All these make Django ORM a killer feature especially when it comes to handling complex databases with very many tables.

    결론

    With that said and more as you will read from other developers, the question still stands, what do you choose?
    Well, I am someone who writes both frameworks and my conclusion is thought about.

    When you are handling something that is not complex at all, please choose Flask.

    If you are working on a project with some other framework such as Express or Laravel, but wanted some independent feature to be done with python, please choose flask.

    Otherwise, choose django.

    좋은 웹페이지 즐겨찾기