Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7500361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:09:19+00:00 2026-05-29T20:09:19+00:00

Is there a way to detect unused templates in a Django project? Before Django

  • 0

Is there a way to detect unused templates in a Django project?

Before Django 1.3, that would have been possible with a simple string-matching function like this one. But since 1.3, there are generic class based views that automatically generate a template_name, if you don’t override it (e.g. DetailView).

Also, if you override 3rd party module templates, those templates aren’t used anywhere directly in your views.

Maybe it could be done by crawling all URL definitions, loading the corresponding views and getting the template_name from them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:09:21+00:00Added an answer on May 29, 2026 at 8:09 pm

    It’s not possible to detect unused templates for certain, even in the absence of generic views, because you can always write code like this:

    get_template(any_code_you_like()).render(context)
    

    So even prior to Django 1.3 the django-unused-templates application you linked to could only have worked for projects that respected some kind of discipline about the use of templates. (For example, always having a string literal as the template argument to functions like get_template and render_to_response.)

    Loading all the views wouldn’t be sufficient either: a view may use different templates under different circumstances:

    def my_view(request):
        if request.user.is_authenticated():
            return render(request, 'template1.html')
        else:
            return render(request, 'template2.html')
    

    And of course templates may not be used by views at all, but by other parts of the system (for example, e-mail messages).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to detect that a CSS background image has been loaded?
Is there a way to detect the last (or first) plugin that has been
Is there any way to detect when an app is no longer active? That
Is there any way to detect all the possible user activities within a WebBrowser
Is there a way to detect that all characters are displayed properly with the
Is there a way to detect that your iPhone app us running 2x/1x on
Is there a way to detect when a window that doesn't belong to my
Is there a way to detect that a DirectShow filtergraph has reached the end
Is there a way to detect, from within the finally clause, that an exception
Is there a way to detect deletion of a file before windows performs the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.