Static analysis tool that finds unused functions, classes, variables, imports and unreachable code in Python projects.
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
Install the plugin from PyPI
pip install pylint-django - 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
A linter that enforces Swift style and conventions, with over 200 rules that can be configured per project.
Self-hosted code quality and security platform that scans projects for bugs, vulnerabilities and maintainability issues, with Quality Gates for CI pipelines.
A set of PHP_CodeSniffer rules that flags code using PHP features or functions that break on other PHP versions.
A Docker image bundling many PHP static analysis, testing and code-quality tools so you can run them without installing PHP tooling locally.
A CLI tool that runs Python linters and formatters such as ruff, isort, black, mypy and flake8 directly on Jupyter Notebooks.