Flask is a great web framework for creating server-side web applications with Python; If you do not have knowledge of using server web frameworks with Python, Flask is a good candidate to start with; Being a microframework, which means that initially it comes with the minimum necessary to be able to function, you can see little by little how the framework works without giving rise to confusion with files, directory structure or modules that you have not placed, as happens with others. more robust frameworks like Django, which when creating a project in Django, has many files and folders.
Although Flask is a microframework does not mean that it should be used for small projects, since it has a large number of extensions that you can configure for the project based on its needs; for example, if you need to send emails, there are already extensions, as well as if you want to log in socially, connect via ftp, user modules, etc.
Flask is a microframework used for the development of web applications in Python, although the term microframework does not confuse you since you can use it to build all kinds of web applications, both small and large. Some of its main features are:
Flask main features
Flask is a great microframework to start developing web applications with Python. Being a microframework, it provides the bare minimum to work without worrying about a structure that is difficult for beginners to follow, as is the case with Django, which makes it an excellent candidate to start with. in this little world.
Among the main features of Flask we have:
- Perfect for developing basic applications that you may want to scale in the future.
- It includes a development server, therefore, we can quickly start developing applications.
- Includes several packages for unit testing.
- It is compatible with WSGI with which we can easily serve our application.
- It uses Python, so we have the entire Python ecosystem at our disposal.
- Its learning curve is quite low if we compare it with other frameworks.
- It is extensible through extensions or plugins created specifically for Flask.
- The minimum to work, Flask is a framework with a fairly low learning curve, being a microframework and bringing the minimum to be able to work, it is quite easy to understand, create our first hello world and scale little by little.
- Age, Flask is a framework that has been on the market for a long time, it is constantly receiving updates to use the latest versions of Python and dependencies in general and incorporate new features.
- Extensions, Flask offers a wide variety of extensions that allow you to add additional functionalities, such as form validation, integration with databases, template engine, among others.
- Community support and good documentation, when you have a question about how to implement some functionality, with a simple search, you will surely be able to find more information about how to
- implement said functionality, having an active community and very good documentation.
These are just some of the main features of Flask, but there are many others.
When installing Flask, several dependencies are installed, among the main ones we have:
- Flask, the microframework known as Flask.
- Jinja2, an excellent templating engine for creating dynamic HTML pages with the help of Python.
- Werkzeug, WSGI (Web Server Gateway Interface) type server used to present the application and be able to consume it through the web browser or similar; It is also used to manage routing, handle HTTP requests and responses, among others.
Guide to take the first steps with Flask 3
Let's start by preparing the environment necessary to create our applications in Flask, which consists of creating the virtual environment using a venv:
First of all, we are going to create a minimal example in Flask, as a microframework that it is, we can create a Hello World with a few lines of code and it is this characteristic that makes Flask a great candidate to start in web framwroks with Python:
The next step is to know how to manage the configuration files to manage different environments as well as the connection parameters to the database, among others:
The next step is to activate debug mode to see the errors that occur when developing the application:
Using Flask Login adds a series of functionalities that we can use to create an authentication system:
Creating ApiRestful is a very common structure that we need to communicate systems, in Flask, we can also create them:
Even in Flask we can create sockets, which means we can create full fuplex communications or from the client to the server and the difference:
It is important to configure CORS in Flask for when you want it to be consumed through a third-party API:
Course and Book to master Flask 3
This guide is intended to take your first steps with Flask using Python; With this, we are going to propose two things:
- It is not a book that aims to know Flask 100%, or from zero to expert, since it would be too big an objective for the scope of this guide, otherwise, to know what it offers us and create the first web applications with Flask , know its extensions, create an API, use Jinja2 among others.
- It is assumed that the reader has at least basic knowledge of Python development.
This book has a practical approach, knowing the key aspects of the technology and moving into practice, gradually implementing small features of an application that has real scope.
To follow this book you need to have a computer with Windows, Linux or MacOS.
The previous resources are mostly practical, we will learn the fundamentals of Flask, knowing its main characteristics based on a small application that we will expand chapter after chapter.
These are just some posts that are available and you can see all the posts in the full list: