To find unused Django views, look for view functions and classes that no urlpatterns entry references, then check templates and string references before you delete them. A whole-project scanner does the first part. Django calls a lot of code by name (views from URLconfs, receivers from decorators, middleware from settings.py, admin methods from list_display strings, model methods from templates), so every scanner needs some configuration before its output is trustworthy.
We built a Django 5.2 app with six known dead items and ran five tools on it. Here's what each found.
The test app
Live code that Django calls for you: a function view and a DetailView in urlpatterns, a ModelAdmin with a list_display method, a @receiver connected in AppConfig.ready(), middleware listed in MIDDLEWARE, a management command, application in wsgi.py, and Product.price_with_tax(), used only in a template.
Dead code:
# shop/views.py (excerpt)
from django.http import HttpResponse, JsonResponse # JsonResponse: unused
def old_landing(request): # in no urlpatterns
return HttpResponse("Welcome to the old shop")
@login_required
def old_account(request): # in no urlpatterns
return HttpResponse("Your account (v1)")
class LegacyReportView(TemplateView): # in no urlpatterns
template_name = "shop/report_v1.html"
def _format_price(value): # never called
return f"${value:,.2f}"
Plus rebuild_search_index() in shop/signals.py, which nothing calls.
Results
| Tool | Dead found (of 6) | Live code flagged | Notes |
|---|---|---|---|
Ruff 0.17.0, ruff check --select F,ARG . | 1 | 4 | Only the unused import; flags signature arguments Django requires (sender, **kwargs, *args, **options) |
Vulture 2.16, vulture . | 6 | 29 | Every setting, both urlpatterns, admin, command, middleware, receiver |
deadcode 2.4.1, deadcode . | 6 | 25 | Similar to Vulture; exits 0 |
Skylos 4.47.1, skylos . | 4 | 13 | Nine settings, application, a list_display method, a template-only method, a view's model attribute |
Skylos 4.47.1, skylos . --confidence 80 | 4 | 2 | application and the view's model attribute |
| Vulture 2.16, configured | 6 | 0 | Config below |
| Skylos 4.47.1, configured | 4 | 0 | Config below |
The two items Skylos missed in every run are old_account (behind @login_required) and LegacyReportView (a class-based view). Both are known gaps in 4.47.1, explained below. If unused class-based views matter to you, use a configured Vulture for that check.
Skylos with defaults
$ skylos . --format concise
shop/admin.py:10 SKY-U001 unused function: ProductAdmin.price_display
shop/models.py:8 SKY-U001 unused function: Product.price_with_tax
shop/signals.py:13 SKY-U001 unused function: rebuild_search_index
shop/views.py:18 SKY-U001 unused function: old_landing
shop/views.py:31 SKY-U001 unused function: _format_price
shop/views.py:2 SKY-U002 unused import: JsonResponse
mysite/settings.py:1 SKY-U003 unused variable: SECRET_KEY
mysite/settings.py:2 SKY-U003 unused variable: DEBUG
mysite/settings.py:3 SKY-U003 unused variable: ALLOWED_HOSTS
mysite/settings.py:4 SKY-U003 unused variable: DEFAULT_AUTO_FIELD
mysite/settings.py:5 SKY-U003 unused variable: INSTALLED_APPS
mysite/settings.py:13 SKY-U003 unused variable: MIDDLEWARE
mysite/settings.py:19 SKY-U003 unused variable: ROOT_URLCONF
mysite/settings.py:20 SKY-U003 unused variable: TEMPLATES
mysite/settings.py:33 SKY-U003 unused variable: DATABASES
mysite/wsgi.py:6 SKY-U003 unused variable: application
shop/views.py:15 SKY-U003 unused variable: model
shop/views.py:28 SKY-U003 unused variable: template_name
shop/views.py:18 SKY-U006 unused parameter: request
It kept live the URL-routed views, the ModelAdmin class, the signal receiver, ShopConfig.ready(), the middleware, the management command and the model fields. The settings scored 60 and the methods named only in strings scored 60, so --confidence 80 drops them.
Skylos, configured
[tool.skylos.whitelist]
names = [
"application", # mysite/wsgi.py, loaded by the WSGI server
"price_display", # named in ProductAdmin.list_display
"price_with_tax", # used in shop/templates/shop/product_detail.html
]
[tool.skylos.overrides."settings.py"]
whitelist = ["*"]
$ skylos . --select SKY-U001,SKY-U002,SKY-U004 --format concise
shop/signals.py:13 SKY-U001 unused function: rebuild_search_index
shop/views.py:18 SKY-U001 unused function: old_landing
shop/views.py:31 SKY-U001 unused function: _format_price
shop/views.py:2 SKY-U002 unused import: JsonResponse
--select limits the first pass to unused functions, imports and classes; class attributes such as model and unused parameters (SKY-U003, SKY-U006) are noisier on Django code.
Two more cases we tested on a copy of the app:
-
A
tests.pymodule. Skylos treats files undertests/ortest/and*_test.pyas tests, not a file calledtests.py, so aTestCaseinshop/tests.pywas reported as an unused class. Fix:[tool.skylos.overrides."tests.py"]withwhitelist = ["*"], or move tests into atests/package. -
@admin.displaymethods named inlist_displaywere reported. Fix:[[tool.skylos.dead_code.entrypoints]] type = "method" decorators = ["admin.display", "admin.action"] reason = "Django admin display and action methods"
With both added, the output was the same four true findings. One caution: in 4.47.1, if pyproject.toml doesn't parse, Skylos ignores the whole [tool.skylos] section without a warning. Check it with python -c "import tomllib; tomllib.load(open('pyproject.toml', 'rb'))".
Vulture, configured
Adam Johnson's 2023 article is the best starting point. Its exclude, ignore_decorators and ignore_names settings, plus a five-line whitelist for the list_display method, the template-only method, a model field and two framework signatures, took Vulture from 29 false positives to none, with all six dead items still reported:
$ vulture
shop/signals.py:13: unused function 'rebuild_search_index' (60% confidence)
shop/views.py:2: unused import 'JsonResponse' (90% confidence)
shop/views.py:18: unused function 'old_landing' (60% confidence)
shop/views.py:22: unused function 'old_account' (60% confidence)
shop/views.py:27: unused class 'LegacyReportView' (60% confidence)
shop/views.py:31: unused function '_format_price' (60% confidence)
The full config and whitelist are in Vulture false positives: tested configs.
Other options, and what each misses
| Option | What it does | What it misses |
|---|---|---|
| Vulture with Adam Johnson's config | Whole-project unused code; the most complete result on our app once configured | Templates; anything you put in ignore_names is hidden everywhere; no transitive dead code |
| django-deadcode 0.8.0 (MIT, Dec 2025) | manage.py finddeadcode maps templates, URL patterns and views: URL names no template links to, templates nothing renders | Unused Python code. On our app it reported one URL name, product-list (the home page, which nothing links to because it's the entry URL), and none of the six dead functions. Needs django_deadcode in INSTALLED_APPS and a BASE_DIR setting |
| django-unused 0.1.4 (last release March 2018) | manage.py unused views / templates | It doesn't run on current Django. On Django 5.2 it failed on import; after we installed its undeclared dependencies six and whoosh, it failed on django.core.urlresolvers, a module removed in Django 2.0 |
| coverage.py and access logs | Runtime evidence: lines that never ran, routes nobody requests | Code your tests or traffic don't exercise looks dead even when it isn't; tests that call dead code make it look alive |
What Skylos treats as used
From the framework rules in the 4.47.1 source, checked against the test app where it has the pattern:
| Django convention | How Skylos treats it |
|---|---|
Function view referenced in any urlpatterns (path, re_path) | Used |
Class-based view used with .as_view(), and its get/post/... methods | Used |
CBV hooks such as get_queryset, get_context_data, form_valid on a class that directly subclasses a Django view | Used |
@receiver(...) handlers and functions passed to signal.connect(...) | Used |
ModelAdmin hooks and option attributes, functions listed in actions=[...], admin.site.register(Model, Admin) and @admin.register | Used |
Model hooks (save, clean, get_absolute_url, natural_key, ...), Meta, fields | Used |
Form clean() and clean_<field>() | Used |
Management command Command, handle, add_arguments | Used |
MiddlewareMixin subclasses and their process_* methods | Used |
Template tags and filters registered with @register.filter, simple_tag, inclusion_tag, tag | Used |
Migration RunPython callbacks | Used |
Celery @shared_task / @app.task | Used |
DRF viewset actions (list, create, retrieve, ...), serializer validate, validate_<field>, to_representation, get_<field> | Used |
The base-class checks look at the direct base. If your view, model or admin inherits from your own base class (a project BaseAdminView, an abstract model), some of that handling no longer applies and you'll see more findings on that class.
What Skylos doesn't find
- Unused class-based views, DRF views and serializers, forms, ModelAdmins and models that directly subclass a Django or DRF base are never reported, even when nothing uses them. Their unused methods are reported; the classes are not.
LegacyReportViewon the test app is an example. - Views behind certain decorators. Unused function views decorated with
@login_required,@permission_required,@staff_member_required,@require_POST,@require_GETor@api_vieware treated as used.old_accounton the test app is an example. - Dead URLconfs. Skylos doesn't follow
include("app.urls")strings. A view listed in a URLconf that nothing includes still counts as used (checked on a copy of the test app, even at--confidence 0). - Receivers that never connect. A
@receiverin a module that is never imported (for example, a missing import inAppConfig.ready()) still counts as used (checked the same way). - Code near
getattrdispatch. If reachable code calls something likegetattr(self, f"do_{action}"), Skylos 4.47.1 stops reporting unused functions anywhere in the project, without a warning (tested on our Flask app). Check the output count before and after adding dynamic dispatch. - Templates. Skylos does not parse Django templates, including
{% url %}tags. A model method or property used only in a template looks unused, so search your templates before deleting one.
Use Skylos for unused function views, helpers, admin actions, tasks, template-tag helpers and unused methods. Use a configured Vulture, or a manual search, for unused class-based views and decorated views. Use access logs for routes nobody calls.
A workflow that holds up
- First pass:
skylos . --confidence 80, or Vulture with the Django config. - Record what Django loads by name: settings,
application,list_displaymethods, template-only methods, admin decorators. - Check templates and strings for each finding:
rg "name" templates/ shop/before deleting a method or view. - Preview removals:
skylos clean . --dry-runlists the unused imports and functions it would delete (here: the import,old_landing,_format_priceandrebuild_search_index);--applywrites them. - Stop new dead code with a pull-request check:
skylos cicd init --no-uploadwrites a GitHub Actions workflow that needs no Skylos account.
For the security side of a Django app, see Django security scanning: what static analysis catches.
Related
- Python dead code detection: find and remove unused code
- Vulture false positives: tested configs for Flask, Django and pytest
- deadcode vs Vulture vs Skylos: tested comparison
- Does Ruff detect dead code?
- Dead-code cleanup PRs that maintainers merged
Try it
pip install skylos
skylos . --confidence 80