Install & Compatibility
Where this runs
tested against v1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 70.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 5.4s · import 0.000s · 71MB
70MB installed
● package 70MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
flake8_django
✓ No direct import needed. flake8 automatically discovers installed plugins.
flake8-django is a plugin, not a library meant for direct import and use in Python code. Its checks are integrated when running the `flake8` command.
Install flake8 and flake8-django. Then, run `flake8 .` from your Django project's root directory. flake8-django's checks (prefixed with 'DJ') will be automatically included in the output. Some rules, like DJ10 and DJ11 (verbose_name checks), are optional and must be explicitly enabled via the `--select` argument or in a `.flake8` configuration file.
import os
# Example Django model for demonstration
# This code would typically be in a models.py file
from django.db import models
class MyModel(models.Model):
# DJ01: Avoid using null=True on string-based fields
name = models.CharField(max_length=255, null=True, blank=True) # Will trigger DJ01
description = models.TextField(default='Default description')
class Meta:
# DJ08: Model does not define __str__ method (implicit)
pass
# To run flake8-django, save the above in a file (e.g., myapp/models.py)
# Then, from your project root in the terminal:
# pip install flake8 flake8-django
# flake8 .
# If specific rules like DJ10/DJ11 are desired:
# flake8 --select=E,F,W,C90,DJ,DJ10,DJ11 .
Debug
Known issues
breakingVersion 1.1.5 dropped support for Python versions below 3.7. Projects still on older Python versions must use an earlier flake8-django release.fixUpgrade to Python 3.7.2 or higher, or pin flake8-django to `<1.1.5`.
affects: <1.1.5
gotchaflake8-django versions require specific flake8 versions for compatibility. v1.1.3 added compatibility for flake8 4.x, and v1.1.5 added compatibility for flake8 5.x. Users might encounter issues if using incompatible versions.fixEnsure your `flake8-django` version is compatible with your `flake8` installation. Consult the GitHub release notes or PyPI for specific compatibility ranges.
affects: All versions, depending on flake8 compatibility
gotchaOptional rules (e.g., DJ10 for `verbose_name`, DJ11 for `verbose_name_plural`) are disabled by default and will not be reported unless explicitly selected.fixEnable optional rules by adding them to the `--select` argument when running `flake8` (e.g., `flake8 --select=...,DJ10,DJ11 .`) or by configuring them in your `.flake8` or `pyproject.toml` file.
affects: All versions
gotchaThe DJ01 check warns against using `null=True` on string-based model fields like `CharField` and `TextField`, which is a common Django anti-pattern.fixFor optional string fields, use `blank=True` and set a `default` value or handle `null` explicitly, as empty strings are usually preferred over `NULL` in databases for string fields. E.g., `name = models.CharField(max_length=255, blank=True, default='')`.
affects: >=1.0.0
Upgrade
Version history
1.4latest on PyPI · released Jul 31, 2023
Audit
Dependencies
flake8requiredflake8-django is a plugin for Flake8 and requires it to run. It is a peer dependency.
DjangorequiredThe plugin analyzes Django-specific code and requires Django to be present in the environment for meaningful checks. It is a peer dependency.
pythonrequiredRequires Python version 3.7.2 or later, but less than 4.0.0.