Analysis for unused code in a Django codebase

This is an idea that has been floating around my head for a long time in various forms. Currently it has been crystalised by me working on a codebase that has a lot of cruft such that URL patterns, views and templates exist, but are not actually currently used.

At a high-level the tool would use the following process:

  1. Analyse all templates, looking for plain internal href attributes and the url tag and then report these.
  2. Then it would collate the urls and match them to the currently defined urlpatterns
  3. Which in turn is linked to views
  4. Which will mention template names again

From the following process the tool could then annotate files or produce a report that would list:

  1. Which views are referenced by a URL (and how many times)
  2. Which URLs are referenced in a template
  3. Which templates are referenced by views.

This is just the start of course, there are going to be templates from include and extend which would could be reported on during the template process or URLs referenced by reverse or redirect in other parts of the codebase.

I think this could be invaluable of getting a birds-eye view of a Django codebase, what do you think?