Category: Flask
-
MagicMock with Python

MagicMock is an essential Python tool for testing, allowing developers to simulate external dependencies like databases and APIs, ensuring unit tests are fast and isolated. It provides flexible mock objects, enabling control over behavior and verification of interactions. Techniques like using the @patch decorator enhance its usability in tests.
-
Python Unittest Mocking Constructors

Writing effective unit tests can be challenging, especially with mocks. The post discusses issues with mocking constructors in Python’s unittest framework, suggesting that imports be structured differently to enable successful mocking. By importing the module instead of the class directly, the @patch decorator can function correctly, allowing for effective testing.
-
SQLAlchemy and JSON values

Storing JSON in a relational database? Sounds like a contradiction, but sometimes, it’s the best solution. SQLAlchemy makes it easy to use a JSON column in Postgres—until you try to update a single value inside it. Turns out, SQLAlchemy doesn’t track those changes by default, leading to silent failures. The fix? Marking the column as…
-
Handle The Errors with Flask Correctly

Effective error management in Flask applications is crucial for security, usability, and debugging. Implement custom exceptions to centralize handling and use blueprints for clean error responses. Additionally, log useful details while avoiding exposing sensitive information. This strategy ensures a better user experience and maintains application integrity.
-
Forgot Password Feature with Python and Flask

The article discusses user authentication options, highlighting the “Forgot Password” feature implementation using JWT in Python and Flask. It outlines a secure workflow for resetting passwords via email, emphasizing the importance of short-lived JWTs for security. Proper authentication procedures enhance user trust and experience in applications.
-
How to Solve the CORS error with Flask

This article addresses the common CORS error faced by web developers when connecting a front-end application to a Flask API. It explains the security reasons behind CORS policies, the role of preflight requests, and provides solutions using Flask-CORS.
-
How to Handle the Database Migrations with Alembic

In this video I will show how to use Alembic to Handle the database migrations. I show and explain the main commands of Alembic.
-
Decorators in Python

In this article I will explain what are the Decorators in Python. And I will also show how I create my own Decorator.
-
Python Logging

In this article I will show how to use the Logging library in Python. I will show how to configure the Logging library for many Handlers, Formatters and Filters.
-
Jinja Templates

In this article, I show how a Flask backend can render and return Jinja templates. I will show how to use variables inside the Jinja templates, blocks and macros.
