<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Albert Brugués, Author at Be on the Right Side of Change</title>
	<atom:link href="https://blog.finxter.com/author/albertbrugues/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.finxter.com/author/albertbrugues/</link>
	<description></description>
	<lastBuildDate>Sat, 28 Aug 2021 10:01:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.finxter.com/wp-content/uploads/2020/08/cropped-cropped-finxter_nobackground-32x32.png</url>
	<title>Albert Brugués, Author at Be on the Right Side of Change</title>
	<link>https://blog.finxter.com/author/albertbrugues/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Flask vs Django: Comparing the Two Most Popular Python Web Frameworks</title>
		<link>https://blog.finxter.com/flask-vs-django-a-comparison-between-the-two-most-popular-python-web-frameworks/</link>
		
		<dc:creator><![CDATA[Albert Brugués]]></dc:creator>
		<pubDate>Sat, 28 Aug 2021 09:45:23 +0000</pubDate>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Flask]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://blog.finxter.com/?p=34470</guid>

					<description><![CDATA[<p>When it comes to developing web applications in Python there are lots of frameworks. Some examples are Pyramid, Web2Py, Bottle or CherryPy, among others. However, the two most popular ones are Flask and Django. We can confirm this fact by having a look at the most starred Python libraries in GitHub: As we will see ... <a title="Flask vs Django: Comparing the Two Most Popular Python Web Frameworks" class="read-more" href="https://blog.finxter.com/flask-vs-django-a-comparison-between-the-two-most-popular-python-web-frameworks/" aria-label="Read more about Flask vs Django: Comparing the Two Most Popular Python Web Frameworks">Read more</a></p>
<p>The post <a href="https://blog.finxter.com/flask-vs-django-a-comparison-between-the-two-most-popular-python-web-frameworks/">Flask vs Django: Comparing the Two Most Popular Python Web Frameworks</a> appeared first on <a href="https://blog.finxter.com">Be on the Right Side of Change</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When it comes to developing web applications in Python there are lots of frameworks. Some examples are Pyramid, Web2Py, Bottle or CherryPy, among others. However, the two most popular ones are <strong>Flask </strong>and <strong>Django</strong>. </p>



<p>We can confirm this fact by having a look at the <a href="https://github.com/search?l=Python&amp;q=stars%3A%3E100&amp;s=stars&amp;type=Repositories" target="_blank" rel="noreferrer noopener">most starred Python libraries in GitHub</a>:</p>



<div class="wp-block-image"><figure class="aligncenter size-full is-resized"><img fetchpriority="high" decoding="async" src="https://blog.finxter.com/wp-content/uploads/2021/08/image-33.png" alt="" class="wp-image-34473" width="767" height="252" srcset="https://blog.finxter.com/wp-content/uploads/2021/08/image-33.png 1023w, https://blog.finxter.com/wp-content/uploads/2021/08/image-33-300x99.png 300w, https://blog.finxter.com/wp-content/uploads/2021/08/image-33-768x252.png 768w" sizes="(max-width: 767px) 100vw, 767px" /></figure></div>



<p>As we will see in this post, both of these frameworks follow very different design principles. Thus, we can not conclude that one is superior to the other. To choose the one that is best for you comes down to which type of application you want to build. In this article we will deep in the advantages and disadvantages of both of these frameworks. Therefore, you can make an informed decision on which one better fits your needs.</p>



<h2 class="wp-block-heading">What is Flask?</h2>



<p>Flask is a microframework conceived to develop web applications in Python. It started in 2010 as an April Fools Day Joke. The key concept in Flask is the word “micro” that refers to the fact that its core is simple but extensible. Because of that it can be learned fast and has a good learning curve. For instance, the Flask hello world app can be written in just five lines of code.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "&lt;p>Hello, World!&lt;/p>"</pre>



<p>And to initialize the server you must type the following command in the terminal, which runs the app by default on the URL <a href="http://127.0.0.1:5000" target="_blank" rel="noreferrer noopener">http://127.0.0.1:5000</a>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ FLASK_APP=hello.py flask run</pre>



<h2 class="wp-block-heading">Flask Advantages and Drawbacks</h2>



<p>Flask has been designed to start web development quickly and easily. This makes it ideal for building prototype applications. The word that best defines it is “minimalism”, as all that Flask includes are four main components: a template engine (named Jinja2), URL routing, error handling and a debugger. That means that a Flask application is <strong>lightweight</strong>. In turn, as it does not have to run a lot of code it is also a little bit <strong>faster </strong>than Django.</p>



<p>But Flask’s <strong>minimalism </strong>does not mean that you can’t build great web applications with it. Instead Flask is <strong>flexible</strong>, like a Lego construction set. All the functionalities expected from a web application like an Object-Relational mapping (ORM), security, authentication, data validation, etc. are delegated to <strong>third-party libraries</strong> that you must choose on. Moreover, there are <strong>extensions </strong>like Flask-Security that bundle together security libraries that people typically use with Flask.</p>



<p>However, Flask’s flexibility comes with many <strong>drawbacks</strong>. First, two Flask applications can follow very different patterns, which means that it can be <strong>hard </strong>for a developer to switch from one to another. Second, as Flask’s extensions are developed by different teams, a Flask app is more prone to <strong>security risks</strong> and requires more time to keep it updated. Last, because of the use of different libraries the documentation that you can find is very spread over the internet.</p>



<h2 class="wp-block-heading">What is Django?</h2>



<p>Django is a “full stack” web framework that can tackle scalable and high quality web applications. It was publicly released in 2005, but it started earlier as a Python CMS at the Lawrence Journal-World newspaper. In contrast with Flask, Django forces you to do things their own way. Thus, it has a steeper learning curve and can be more intimidating to beginners.</p>



<p>A Django application involves at least the use of three files, and four when a data model is involved. To create a hello world application with Django is as follows.</p>



<p>First, we create a Django project in a folder called <code>config</code>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ django-admin startproject config .</pre>



<p>We then create an app named pages by typing the following command. This creates a pages folder, located at the same level of the config folder, containing different files.&nbsp;</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py startapp pages</pre>



<p>In the next step we update the file <code>pages/views.py</code> to make it look as follows:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.http import HttpResponse

def helloPageView(request):
    return HttpResponse("Hello, World!")</pre>



<p>Then we update the file <code>pages/urls.py</code> with the following code:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.urls import path
from .views import helloPageView

urlpatterns = [
    path('', helloPageView, name='home')
]
</pre>



<p>The last file to update is the <code>config/urls.py</code> file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('pages.urls'))
]
</pre>



<p>Finally, we can run our Django hello world application with the following command, which starts the server on the URL <a href="http://127.0.0.1:8000" target="_blank" rel="noreferrer noopener">http://127.0.0.1:8000</a>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py runserver</pre>



<p>As we have seen in this example, the hello world Django application involves much more steps than the same application with Flask.</p>



<h2 class="wp-block-heading">Django Advantages and Drawbacks</h2>



<p>Django follows the principle of “Don’t Repeat Yourself” and includes all the components that are needed to build a web application. It has out of the box templating, forms, routing, authentication, database administration among other features. It requires <strong>less decisions</strong> to be made by you. Because of that, an experienced Python developer who wants to dig into web development can do it in a relatively short amount of time. This also means that Django projects follow a pattern making them very similar one to another.</p>



<p>When you use Django you are <strong>forced to use its ORM</strong>, which assumes that you are going to use a relational database. It officially supports databases like MariaDB, MySQL or SQLite among others. With Django’s ORM you can do almost every operation that an ordinary web app needs. In addition to that, it allows you to write your own SQL queries. The negative side of it is that you can forget about using a NoSQL database like MongoDB with Django.</p>



<p>In terms of security, Django is <strong>very reliable </strong>as it incorporates features like protection against SQL injection and cross site scripting (XSS) attacks, the possibility to enable HTTPS protection, or JSON web tokens (through external libraries). So it is very suitable for applications that require their users to authenticate or that involve monetary transactions. </p>



<p>Another great aspect of Django is its community. As a popular web framework, Django has a <strong>very big community</strong> with lots of documentation available online. For instance it has more than 200k tagged questions on Stack Overflow. </p>



<p>But the Django way of doing things, handling everything for you, can also be a drawback as it produces <strong>monolithic servers</strong> that act as a single unit. This means that it is not possible to develop a microservice architecture with Django.</p>



<h2 class="wp-block-heading">Differences Side by Side</h2>



<p>As a summary these are the main differences between Flask and Django.</p>



<figure class="wp-block-table"><table><tbody><tr><td></td><td><strong>Flask</strong></td><td><strong>Django</strong></td></tr><tr><td><strong>Type of framework</strong></td><td>Microframework with lightweight code</td><td>Full stack, provides everything you need</td></tr><tr><td><strong>Learning</strong></td><td>Easy to learn</td><td>Steeper learning curve</td></tr><tr><td><strong>Project size</strong></td><td>For smaller and less complicated projects</td><td>For larger projects</td></tr><tr><td><strong>Project layout</strong></td><td>Arbitrary</td><td>Follows a pattern</td></tr><tr><td><strong>Templates</strong></td><td>Relies on Jinja2 engine</td><td>Built-in engine</td></tr><tr><td><strong>Databases</strong></td><td>Lack of ORM but can work with many different databases through libraries</td><td>Own ORM for relational databases like MariaBD, MySQL, SQLite, etc.</td></tr><tr><td><strong>Admin</strong></td><td>Can be done with the Flask-Admin extension</td><td>Built-in panel for admin tasks</td></tr><tr><td><strong>Security</strong></td><td>Depends on the security of external libraries</td><td>Built-in security features</td></tr><tr><td><strong>API</strong></td><td>Supports API</td><td>Does not support API</td></tr><tr><td><strong>Flexibility</strong></td><td>Very flexible, allowing developers to add their own libraries</td><td>Low, developers must follow Django’s rules</td></tr><tr><td><strong>Performance</strong></td><td>Slightly better</td><td>Sufficient for any application</td></tr></tbody></table><figcaption><strong>Table</strong>: Flask vs Django</figcaption></figure>



<h2 class="wp-block-heading">What in Terms of Freelance Projects?</h2>



<p>As you might know, <a href="https://blog.finxter.com/full-time-python-freelancer/" title="How to Go Full-Time ($3000/m) as a Python Freelancer﻿" target="_blank" rel="noreferrer noopener">Finxter.com promotes remote work</a> by helping people to start their careers as Python freelance developers. Two well established <a href="https://blog.finxter.com/what-are-the-best-freelancing-sites/" target="_blank" rel="noreferrer noopener" title="What Are the Best Freelancing Sites for Coders?">websites</a> where freelancers can apply to projects posted by companies are <a href="https://freelancer.com/" target="_blank" rel="noreferrer noopener" title="https://freelancer.com/">Freelancer.com</a> and <a href="https://upwork.com" target="_blank" rel="noreferrer noopener" title="https://upwork.com">Upwork</a>.</p>



<p>At the time of writing, we can find at Freelancer.com 82 projects when we search for the keyword Django and 14 projects when we search for Flask.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh5.googleusercontent.com/eDEQmr-k6TazodoK_yiHEGau_nPd3_OpeCMIoUwgrbvFxjTQu0sUCJPL-SZyCJ-jL2tyzBVEw9nPNmwZXO5iii3ob3-XALOdLWVGHCJFmlUlPa_YOv8MKjbeh4BTlcM5mpF4AncK=s0" alt=""/><figcaption><strong>Figure</strong>: Freelancer.com has 82 Django gigs</figcaption></figure></div>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh4.googleusercontent.com/XbnLNBYpoC5uZC5NMu4ifal4ep9wUqH4ZZMznFL6NYPg98PjwYh0XrRfqcayylju2YrUp3B484O-fP_0zVlip0MNf7v2bk5uy_IOF6wFgVoqZFMV4o2ZppWGSYAwWnaA5faZnKws=s0" alt=""/><figcaption> <strong>Figure</strong>: Freelancer.com has 14 Flask gigs</figcaption></figure></div>



<p>If we look at Upwork the number of projects are higher for both frameworks. In particular, we find 717 Django projects and 336 Flask projects.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh6.googleusercontent.com/JakS39bMibcs6VRR0wmPZwmtCo-UbVohIIXc9UCOMYTX7jvRQOq12VbgLZtNM_Xn61HecO69r8gwiQFyCgHHAP3J6l4fkX0F3JTFWJijDzylvn1ABzQ1LaS_3ZtIFt_HStT3K734=s0" alt=""/><figcaption> <strong>Figure</strong>: Upwork has 717 Django gigs </figcaption></figure></div>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh4.googleusercontent.com/uJPTQMhP5RQ21v1SwmX7MFydRYVbYTJg5lygC21sxBpAi1sLLEVbhH-o7Cks2WDUuX5-1xo-f6eZPhGJMnj08bR8u-d8SAl9Uw_JsQ12OxPeWIZs3SDgIFaNlrynRTnNgLGSU6PD=s0" alt=""/><figcaption>  <strong>Figure</strong>: Upwork has 336 Flask gigs  </figcaption></figure></div>



<p>We see that Upwork has a substantially higher number of projects to apply in terms of <a href="https://blog.finxter.com/how-to-build-and-host-your-python-web-app-for-free/" target="_blank" rel="noreferrer noopener" title="How to Build and Host Your Python Web App for Free">Python web development</a>. We also see a higher number of Django projects on both websites .</p>



<p>However, the above numbers are snapshots and can vary depending on the time we take them. But if we look at time series like worldwide searches of Flask and Django in the last five years, provided by Google trends, we can confirm that there is a higher interest in Django.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh4.googleusercontent.com/dzj9ZJoRfAwm9Slyu4tocjploixK3s-I8DEdbnnjkgO83jVOhpR0ZEmrKc2yOMkLlH6b8im6lRRvrgnQXaepqbyTGfzZhMsd5_Jx_09WersonyFWCevosB4_C56xTPhtctLCADoj=s0" alt=""/><figcaption>  <strong>Figure</strong>: Django is still more popular than Flask.</figcaption></figure></div>



<h2 class="wp-block-heading">When to Use One or the Other?</h2>



<p>As we have seen in this post Flask and Django are two sides of the same coin. Now that we know all that they offer, this is my recommendation on which cases are best to use one or the other.</p>



<p><strong>Better to use Flask if:</strong></p>



<ul class="wp-block-list"><li>You are new to Python.</li><li>You just want to build a simple prototype application.</li><li>You want to know how your application works and operates internally.</li><li>Your application is based on NoSQL.</li><li>You plan to build a microservice architecture.</li><li>You want to build simple web apps like REST APIs, IoT apps or small websites with static content.</li></ul>



<p><strong>But you better use Django if:</strong></p>



<ul class="wp-block-list"><li>You are already experienced in Python.</li><li>Your application will use a SQL database.</li><li>Your application will have users that need to be authenticated.</li><li>You want an application with user administration panels.</li><li>Your application will serve dynamic content.</li></ul>



<p></p>
<p>The post <a href="https://blog.finxter.com/flask-vs-django-a-comparison-between-the-two-most-popular-python-web-frameworks/">Flask vs Django: Comparing the Two Most Popular Python Web Frameworks</a> appeared first on <a href="https://blog.finxter.com">Be on the Right Side of Change</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: blog.finxter.com @ 2026-06-14 04:27:12 by W3 Total Cache
-->