Articles, news, and tips on Django and Python

Class-based vs Function-based Views in Django

In this article, we'll look at the differences between Django's class-based views (CBV) and function-based views (FBV). We'll compare and contrast and dive into the pros and cons of each approach (along with Django's built-in generic class-based views). By the end, you should have a good understanding of when to use one over the other.

Python Constants: Improve Your Code's Maintainability

In programming, the term constant refers to names representing values that don’t change during a program’s execution. Constants are a fundamental concept in programming, and Python developers use them in many cases. However, Python doesn’t have a dedicated syntax for defining constants. In practice, Python constants are just variables that never change.

Parallelism, Concurrency, and AsyncIO in Python - by example

This tutorial looks at how to speed up CPU-bound and IO-bound operations with multiprocessing, threading, and AsyncIO.

Modern Python: start a project with pyenv & poetry

Here we'll look at how to use Pyenv to manage and install different versions of Python, and Poetry to manage packages and virtual environments.

Python Project Workflow

In this article, you'll glue everything together as you develop a single project from start to finish. After developing the basic project, you'll: Wire up CI/CD with GitHub Actions, Configure coverage reporting with CodeCov, Publish the package to PyPi and the docs to Read the Docs, Update PyPI and Read the Docs via GitHub Actions

Python Project Setup – Virtual Environments and Package Management

Virtual Environments are isolated Python environments that have their own site-packages. Basically, it means that each virtual environment has its own set of dependencies to third-party packages usually installed from PyPI.

Advanced usage of Python requests - timeouts, retries, hooks

The Python HTTP library requests is probably my favourite HTTP utility in all the languages I program in. It's simple, intuitive and ubiquitous in the Python community. Most of the programs that interface with HTTP use either requests or urllib3 from the standard library.

Understanding Decorators in Python

Decorators are wrappers around Python functions (or classes) that change how these classes work. A decorator abstracts its own functioning as far away as possible. The Decorator notation is designed to be as minimally invasive as possible. A developer can develop his code within his domain as he is used to and only use the decorator to extend the functionality. Because this sounds very abstract, let’s look at some examples.

Understanding Attributes, Dicts and Slots in Python

Python is a very dynamic language by nature. Variables do not need to be declared and can be added as attributes almost everywhere.

A Comprehensive Guide to Slicing in Python

In Python, some objects like strs or lists can sliced. For example, you can get the first element of a list or a string.

Django 4.0 released

The Django team is happy to announce the release of Django 4.0.

Securely Deploy a Django App With Gunicorn, Nginx, & HTTPS

Taking a Django app from development to production is a demanding but rewarding process. This tutorial will take you through that process step by step, providing an in-depth guide that starts at square one with a no-frills Django application and adds in Gunicorn, Nginx, domain registration, and security-focused HTTP headers. After going over this tutorial, you’ll be better equipped to take your Django app into production and serve it to the world.

Automatically Retrying Failed Celery Tasks

In this article, we'll look at how to automatically retry failed Celery tasks.

Django REST Framework and Elasticsearch

In this tutorial, we'll look at how to integrate Django REST Framework (DRF) with Elasticsearch. We'll use Django to model our data and DRF to serialize and serve it. Finally, we'll index the data with Elasticsearch and make it searchable.

Dockerizing Django with Postgres, Gunicorn, and Nginx

This is a step-by-step tutorial that details how to configure Django to run on Docker with Postgres. For production environments, we'll add on Nginx and Gunicorn. We'll also take a look at how to serve Django static and media files via Nginx.

Asynchronous Tasks with Django and Celery

If a long-running process is part of your application's workflow, rather than blocking the response, you should handle it in the background, outside the normal request/response flow.

Django security releases issued: 3.2.4, 3.1.12, and 2.2.24

In accordance with our security release policy, the Django team is issuing Django 3.2.4, Django 3.1.12, and Django 2.2.24. These release addresses the security issue detailed below. We encourage all users of Django to upgrade as soon as possible.

Django bugfix releases issued: 3.2.3, 3.1.11, and 2.2.23

Today we've issued 3.2.3, 3.1.11, and 2.2.23 bugfix releases. The release package and checksums are available from our downloads page, as well as from the Python Package Index. The PGP key ID used for this release is Mariusz Felisiak: 2EF56372BA48CD1B.

Effectively Using Django REST Framework Serializers

In this article, we'll look at how to use Django REST Framework (DRF) serializers more efficiently and effectively by example. Along the way, we'll dive into some advanced concepts like using the source keyword, passing context, validating data, and much more.

Django security releases issued: 3.2.2, 3.1.10, and 2.2.22

In accordance with our security release policy, the Django team is issuing Django 3.2.2, Django 3.1.10, and Django 2.2.22. These releases address the security issue with severity "moderate" detailed below. We encourage all users of Django to upgrade as soon as possible.