Repolode
pylint-dev

pylint-dev/pylint-django

A Pylint plugin that teaches Pylint about Django models, forms, views and migrations to cut false positives in Django code.

Stars
623
Forks
124
Open issues
76
Last commit
4 days ago

What is it?

pylint-django is a plugin for Pylint, the Python static analyser. Out of the box, Pylint does not understand Django's runtime magic, so it reports warnings for attributes like Model.objects or Views.request, and for ForeignKey fields it cannot resolve. This plugin adds Django-aware inference so those false positives go away and attribute types on model and form fields are known.

The plugin works by loading with Pylint's --load-plugins option. For accurate results it needs your Django settings module, passed either through the DJANGO_SETTINGS_MODULE environment variable or the --django-settings-module flag, so it can resolve installed apps and string-referenced models. Without settings, it falls back to defaults and inference is less precise. It is also bundled with the Prospector linter and activates automatically when Django is detected.

An optional migrations checker flags newly added fields with defaults, which can be slow on large tables, and RunPython operations lacking a reverse callable. It is disabled by default and must be enabled explicitly.

Key features

  • 01Suppresses false warnings for Django-generated attributes such as Model.objects and Views.request.
  • 02Resolves ForeignKey attributes so they no longer trigger 'has no member' errors.
  • 03Infers types of Model and Form field attributes.
  • 04Validates Model.__unicode__ methods and flags dangerous ModelForm exclude usage.
  • 05Optionally checks migrations for risky field defaults and non-reversible RunPython operations.

Use cases

  • Running Pylint or Prospector in CI on a Django project without drowning in false positives.
  • Improving static analysis accuracy for Django models and forms in large codebases.
  • Reviewing migration files for performance or reversibility problems before deployment.

Quick start

  1. 1

    Install the plugin from PyPI

    pip install pylint-django
  2. 2

    Run pylint with the plugin loaded and your Django settings module

    pylint --load-plugins pylint_django --django-settings-module=your.app.settings [..other options..] <path_to_your_sources>

Things to know

  • Licensed under GPL-2.0, a copyleft license that may restrict some commercial use.
  • Django is not installed by default and must be set up separately, or installed via the with-django extra.
  • Works best with a configured Django settings module; without one, analysis is less accurate.

Topics

FAQ

What is pylint-django?
A Pylint plugin that teaches Pylint about Django models, forms, views and migrations to cut false positives in Django code. pylint-django is a plugin for Pylint, the Python static analyser. Out of the box, Pylint does not understand Django's runtime magic, so it reports warnings for attributes like Model.objects or Views.request, and for ForeignKey fields it cannot resolve. This plugin adds Django-aware inference so those false positives go away and attribute types on model and form fields are known.
Is pylint-django free to use? What license does it have?
pylint-django is open source under the GPL-2.0 license. Check the license terms before using it in commercial products.
Is pylint-django still maintained?
Actively maintained. The last commit to pylint-django was on Nov 3, 2026.
What can I use pylint-django for?
Running Pylint or Prospector in CI on a Django project without drowning in false positives. Improving static analysis accuracy for Django models and forms in large codebases. Reviewing migration files for performance or reversibility problems before deployment.
How do I install pylint-django?
Install the plugin from PyPI: pip install pylint-django Run pylint with the plugin loaded and your Django settings module: pylint --load-plugins pylint_django --django-settings-module=your.app.settings [..other options..] <path_to_your_sources>
Where can I get pylint-django?
The source code and installation instructions are on GitHub: https://github.com/pylint-dev/pylint-django

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects