flake8-django

1.4 · active · verified Thu Apr 16

flake8-django is a plugin for the Flake8 static code analysis tool, specifically designed to detect bad practices and enforce style guidelines within Django projects. Currently at version 1.4, it sees active, though irregular, development with its last major release in July 2023.

Common errors

Warnings

Install

Imports

Quickstart

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 .

view raw JSON →