Flask
-
How To Perform Unit Testing in Flask
Introduction Testing is essential to the software development process, ensuring that code behaves as expected and is defect-free. In Python, pytest is a popular testing framework that offers several advantages over the standard unit test module, which is a built-in Python testing framework and is part of the standard library. pytest includes a simpler syntax, better output, powerful fixtures, and a rich plugin ecosystem. This tutorial will guide you through setting up a Flask application, integrating pytest fixtures, and writing…
-
How To Create a REST API with Flask on Ubuntu
Introduction In this tutorial, you will learn how to create a simple REST API using Flask, a lightweight Python web framework. We’ll cover the basics of setting up a Flask application, defining routes, handling requests, and returning JSON responses. By the end of this tutorial, you will have a working API that you can extend and integrate with other applications. Prerequisites A server running Ubuntu and a non-root user with sudo privileges and an active firewall. For guidance on how…
-
How To Handle Errors in a Flask Application
The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program. Introduction Flask is a lightweight Python web framework that provides useful tools and features for creating web applications in the Python Language. When you’re developing a web application, you will inevitably run into situations where your application behaves in a way contrary to what you expected. You might misspell a variable, misuse a for loop, or construct an if…
-
How To Use Templates in a Flask Application
The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program. Introduction Flask is a lightweight Python web framework that provides useful tools and features for creating web applications in the Python Language. When developing a web application, it is important to separate business logic from presentation logic. Business logic is what handles user requests and talks to the database to build an appropriate response. Presentation logic is how the…
-
How To Create Your First Web Application Using Flask and Python 3
The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program. Introduction Flask is a lightweight Python web framework that provides useful tools and features for creating web applications in the Python Language. It gives developers flexibility and is an accessible framework for new developers because you can build a web application quickly using only a single Python file. Flask is also extensible and doesn’t force a particular directory structure…
-
How To Use Web Forms in a Flask Application
The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program. Introduction Web forms, such as text fields and text areas, give users the ability to send data to your application to use it to perform an action, or to send larger areas of text to the application. For example, in a social media application, you might give users a box where they can add new content to their pages.…
-
How To Use Many-to-Many Database Relationships with Flask-SQLAlchemy
The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program. Introduction Flask is a lightweight Python web framework that provides useful tools and features for creating web applications in the Python Language. SQLAlchemy is an SQL toolkit that provides efficient and high-performing database access for relational databases. It provides ways to interact with several database engines such as SQLite, MySQL, and PostgreSQL. It gives you access to the database’s…
-
How To Query Tables and Paginate Data in Flask-SQLAlchemy
The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program. Introduction Flask is a lightweight Python web framework that provides useful tools and features for creating web applications in the Python Language. SQLAlchemy is an SQL toolkit that provides efficient and high-performing database access for relational databases. It provides ways to interact with several database engines such as SQLite, MySQL, and PostgreSQL. It gives you access to the database’s…
-
How To Use a PostgreSQL Database in a Flask Application
The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program. Introduction In web applications, you usually need a database, which is an organized collection of data. You use a database to store and maintain persistent data that can be retrieved and manipulated efficiently. For example, in a social media application, you have a database where user data (personal information, posts, comments, followers) is stored in a way that can…