Articles, news, and tips on Django and Python

Django Session-based Auth for Single Page Apps

In this article, we'll look at how to authenticate Single-Page Applications (SPAs) with session-based authentication. We'll be using Django for our backend while the frontend will be built with React, a JavaScript library designed for building user interfaces.

Securing a Containerized Django Application with Let's Encrypt

How do I set up an SSL Certificate for a Django application? In this tutorial, we'll look at how to secure a containerized Django app running behind an HTTPS Nginx proxy with Let's Encrypt SSL certificates. This tutorial builds on Dockerizing Django with Postgres, Gunicorn, and Nginx. It assumes you understand how to containerize a Django app along with Postgres, Nginx, and Gunicorn.

What Is the Python Global Interpreter Lock (GIL)?

The Python Global Interpreter Lock or GIL, in simple words, is a mutex (or a lock) that allows only one thread to hold the control of the Python interpreter. This means that only one thread can be in a state of execution at any point in time. The impact of the GIL isn’t visible to developers who execute single-threaded programs, but it can be a performance bottleneck in CPU-bound and multi-threaded code.

Python's Instance, Class, and Static Methods

In this tutorial I’ll help demystify what’s behind class methods, static methods, and regular instance methods. If you develop an intuitive understanding for their differences you’ll be able to write object-oriented Python that communicates its intent more clearly and will be easier to maintain in the long run.

Deploying Django to AWS with Docker and Let's Encrypt

In this tutorial, we'll deploy a Django app to AWS EC2 with Docker. The app will run behind an HTTPS Nginx proxy that uses Let's Encrypt SSL certificates. We'll use AWS RDS to serve our Postgres database along with AWS ECR to store and manage our Docker images.

Customizing the Django Admin

Django's automatically generated admin site is one of the biggest strengths of the framework. The centralized admin interface lets you easily view and manipulate your models' data. This can save you a lot of time while developing and managing content.

Storing Django Static and Media Files on Amazon S3

Amazon's Simple Storage System (S3) provides a simple, cost-effective way to store static files. This tutorial shows how to configure Django to load and serve up static and user uploaded media files, public and private, via an Amazon S3 bucket.

How to Use Python Data Classes in 2023

In Python, a data class is a class that is designed to only hold data values. They aren't different from regular classes, but they usually don't have any other methods. They are typically used to store information that will be passed between different parts of a program or a system.

Python Import from File – Importing Local Files in Python

There are many reasons you might want to import files in Python. Perhaps you're doing data analysis, custom file processing, file manipulation, automation and so on. Fortunately, Python provides a number of ways and methods to help you accomplish this task.

Python List to String – How to Convert Lists in Python

Whether you need to save a list as a text file, display it in a user-friendly format, or pass it as a parameter to a function, knowing how to convert a list to a string is essential. In this tutorial, we will explore various methods to convert Python lists to strings. I'll give you step-by-step instructions for each method, ensuring that you can easily follow along regardless of your programming expertise.

Python Env Vars – How to Get an Environment Variable in Python

Environment variables play a crucial role in Python programming. They provide a way to store and access configuration values, system-specific information, and sensitive data. In this article, we will explore various methods to retrieve environment variables in Python and discuss best practices for handling and managing them effectively.

How to interact with web services using Python

An API, or Application Programming Interface, is an interface that lets you retrieve and send data using code. We mostly commonly use APIs to retrieve data, and that will be the focus of this beginner-friendly tutorial.

How to Use the JSON Module in Python

JSON (JavaScript Object Notation) is a popular, lightweight data interchange standard. It represents data structures made up of key-value pairs that's quite straightforward and human-readable.

Python Decorators Explained For Beginners

In the world of Python programming, decorators can be an elegant and powerful tool in the hands of experienced developers. Decorators give you the ability to modify the behavior of functions without altering their source code, providing a concise and flexible way to enhance and extend their functionality.

How to Check if a Key Exists in a Dictionary in Python – Python Dict Has Key

When working with dictionaries, it's a common practice to check if a key exists or not. This can be most helpful when you are working with a large dataset and need to access values based on their keys. In this article, we are going to explore different ways that we can use to check if a key exists in a dictionary in Python. Let's get started.

How to Use a Foreign Key to Create Many-to-One Relationships in Django

In Django, there are three main types of relationships: one-to-one, many-to-one, and many-to-many. In this article, I will explain the many-to-one relationship in Django. If you are a beginner with some knowledge about Django project setup or even have some decent experience in Django, you can follow along with this article.

How Arrays Work in Python – Array Methods Explained with Code Examples

In this tutorial, you'll learn what an array is in Python. You'll also learn some possible ways to add elements to an existing array.

How to Measure Django Code Quality Using SonarQube, Pytest, and Coverage

We're going to dive deep into the realm of Django code quality assessment. In this comprehensive guide, I'll walk you through an in-depth approach to measuring the code quality of your Django-based application.

Web Security in Django – How to Build a Secure Web Application

Web security is an important aspect of the web application development process. Especially as more data is stored, managed, and shared. As a web developer, it's essential to prioritize security measures to protect your company’s users and data from potential threats.

Mocking External APIs in Python

However, the added value also comes with obstacles. You do not own the external library, which means that you cannot control the servers that host it, the code that comprises its logic, or the data that gets transferred between it and your app. On top of those issues, users are constantly manipulating the data through their interactions with the library.