Tutorial to prepare the environment and start developing applications in Flask

- Andrés Cruz

En español
Tutorial to prepare the environment and start developing applications in Flask

In this tutorial we are going to learn how to install Flask on our computer, regardless of the operating system in which you are; since Flask is cross-platform since it is supported in Python; but before this, let's introduce what is Flask?

What is Flask?

According to the official documentation that you can find at the following link: it is a microframework based on Jinja2 and Werkzeug; here are several slightly strange words that we are going to address next.

Flask is a small framework (a micro framework) that provides the necessary tools and functions to create our applications, it contains the minimum, such as a template engine and HTTP routing and access, and all this with Python as the programming language supported by this framework.

What is a microframework?

A microframework simply means that the framework only contains the basics to be able to function; If you also develop in CodeIgniter of which we have a lot of information on our blog, you will know that CodeIgniter is a small framework with many features but lacks a few.

Flask in its basic definition is simpler than CodeIgniter, it does not have libraries or modules for emails, user control, etc; we only have the routing of the functions and the definition of the templates, and of course, access to the entire Python API, since the framework is written in this programming language.

Flask is extensible: The microframework with which to create large projects

What has been said in the previous paragraph does not mean that flask is only useful for basic development, on the contrary, it is extensible through modules that we can install through the package management tool or python modules, and we have modules of all kinds as we detail and explain. the most important in the most complete course on Flask in Spanish:

When you get to know Flask, you will realize that it has nothing to envy to other frameworks like Django, it is a complete framework with which to develop all kinds of applications, simple and not so simple.

Jinja2 and Werkzeug

Jinja2 is the template engine that Flask uses and the Werkzeug is the library that contains different uses or functions for HTTP, such as the definition of routes, redirections, etc: it is also our WSGI, which is the Python interface that allows us to communicate through http

Why Python Flask?

Surely when you hear web programming with Python, Django comes to mind, which is an excellent web framework for Python that already contains everything necessary to make our apps, but Flask, being the minimum expression of a framework or microframework, we have more control over the different elements of our framework, install just what you need, and it's easier to learn than Django. This does not mean that Flask is better than Django or vice versa, they are simply two different versions for the same goal, which is the development of web apps with Python; in my opinion, Flask works great for us in small or medium-sized projects, while we could use Django for larger projects.

"Flask Python has been the CodeIgniter of php and Django has been the Laravel of php"

Para cerrar esta sección, te muestro una pequeña y mínima app en Flask:

@app.route('/') def hello_world():    return 'Hola mundo Flask' 

And this is all we need to say hello world in Flask (of course once the framework is installed); a file with the previous definition, where we have the routing thanks to our Werkzeug, the function that has been the action or function of our controller and the response that is simply a text and therefore at this moment we are not using the engine Jinja2 templates; now, in django we need a lot more than this to start working and from here what was previously commented

Why learn Python and Flask to develop our applications?

Python is an exceptional language, it is used by companies as important as Microsoft that have free courses on how to start in this programming language, it is fast, multiplatform and easy to learn compared to others like the old Java.

And the best of all

It is that if you know Python you can create, from desktop apps, games, Artificial Intelligence (AI) probabilities procedures and of course, create web apps as we mentioned before; Inclusively, Python is the programming language selected to create the famous Blender.

Therefore, it is an exceptional language, in constant growth and what better way to use it in web programming, which is the creation of systems that are in constant demand and growth, in such a way that with this you can have multiple advantages such as professional growth , since in short, Flask is the best web framework that you can select if you are learning to program and/or creating your first web apps in general or based on Python.

Install Flask for Python

Finally we are going to get to the point that interests us, installing Flask, which since Python is multiplatform, remember that just having Python in its latest versions is enough to follow this guide and with this get your Flask; To install Flask we can do it using pip: pip install flask

And with this we are ready, with executing the following command:

pip freeze | grep flask

You will see the version of Flask you have installed; and with this you can continue with the following tutorial:

Extra: selecting the editor

Now, for the editor you can use whatever you feel comfortable with to work with Python but I personally recommend Visual Studio Code, which is multiplatform and you can develop all kinds of projects based on other frameworks in the same editor.

Andrés Cruz

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.