Django-Specific Code Smells: Catalog, Prevalence, and Automated Detection

  • Leopoldo Teixeira UFPE
  • Eduardo Luiz Silva UFPE

Resumo


Django is a widely used Pythonweb framework for database-backed application development. As with any actively used framework, Django projects can accumulate code smells: patterns that do not break functionality but signal design or implementation choices likely to hurt maintainability, readability, or performance. Existing Django-aware static analysis tools primarily target schema- and configuration-level issues, leaving performance-oriented and behavioral smells largely unaddressed. This paper investigates three research questions concerning such smells: their provenance in a catalog derived from Django-focused grey literature, their prevalence in real-world projects, and the reliability of their automated detection. To answer these questions, we built a static analysis tool that detects five Django-specific smells spanning the Model, View, and Template layers, using Python’s built-in ast module for checks within Python code and a lightweight regex-based tokenizer over HTML templates. We applied the tool to a sample of 33 public Django repositories of varying size, where it flagged 4157 occurrences across the five smells; a manual inspection of 50 flagged occurrences (44 of them genuine, 88% overall) indicates detection reliability is reasonable overall but uneven across smells.

Palavras-chave: Code Smells, Static Analysis, Django, Software Quality

Referências

Maurício Aniche, Gabriele Bavota, Christoph Treude, Marco Aurélio Gerosa, and Arie van Deursen. 2018. Code Smells for Model-View-Controller Architectures. Empirical Software Engineering 23, 4 (2018), 2121–2157. DOI: 10.1007/s10664-017-9540-2

Carl Crowder. 2024. Prospector: Python Static Analysis Tool. [link]. Accessed: 2026-07-10.

Ozren Dabić, Emad Aghajani, and Gabriele Bavota. 2021. Sampling Projects in GitHub for MSR Studies. In 18th IEEE/ACM International Conference on Mining Software Repositories (MSR 2021). IEEE, 560–566. DOI: 10.1109/MSR52588.2021.00073

Django Software Foundation. 2024. Class-Based Views, Django Documentation (6.0). [link]. Accessed: 2026-07-10.

Django Software Foundation. 2024. Django Documentation (6.0). [link]. Accessed: 2026-07-10.

djLint. 2024. djLint: HTML Template Linter and Formatter. [link]. Accessed: 2026-07-10.

Martin Fowler. 1999. Refactoring: Improving the Design of Existing Code. Addison-Wesley, Boston, MA, USA.

Goutom Roy. 2019. Django select_related and prefetch_related. [link]. Accessed: 2026-07-10.

Fernando Kamei, Gustavo Pinto, Igor Wiese, Márcio Ribeiro, and Sérgio Soares. 2021. What Evidence We Would Miss If We Do Not Use Grey Literature?. In Proceedings of the 15th ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM). ACM, 24:1–24:11. DOI: 10.1145/3475716.3475777

Fernando Kamei, Igor Wiese, Crescencio Lima, Ivanilton Polato, Vilmar Nepomuceno, Waldemar Ferreira, Márcio Ribeiro, Carolline Pena, Bruno Cartaxo, Gustavo Pinto, and Sérgio Soares. 2021. Grey Literature in Software Engineering: A critical review. Information and Software Technology 138 (2021), 106609. DOI: 10.1016/J.INFSOF.2021.106609

Fernando Kenji Kamei. 2022. Understanding and Supporting the Decision-Making Whether to Use Grey Literature in Software Engineering Research. Ph.D. Thesis. Universidade Federal de Pernambuco, Centro de Informática, Recife, Brazil.

Lamb, Chris. 2010. django-lint. [link]. Accessed: 2026-07-10.

Manuel Matosevic. 2022. Using Django bulk_create and bulk_update. [link]. Accessed: 2026-07-10.

pylint-dev. 2024. Pylint. [link]. Accessed: 2026-07-10.

Python Code Quality Authority. 2024. Bandit: A Security Linter for Python Code. [link]. Accessed: 2026-07-10.

Python Code Quality Authority. 2024. Flake8: Your Tool for Style Guide Enforcement. [link]. Accessed: 2026-07-10.

Python Code Quality Authority. 2024. pylint-django. [link]. Accessed: 2026-07-10.

Python Software Foundation. 2024. ast — Abstract Syntax Trees, Python Documentation. [link]. Accessed: 2026-07-10.

Qodo AI. 2023. Django Templates: Best Practices for Web Development. [link]. Accessed: 2026-07-10.

Rondelli, Michele. 2024. Radon: Code Metrics for Python. [link]. Accessed: 2026-07-10.

Sabchuk, Michel. 2021. Load Large Sets of Data into a Postgres Database Using Python/Django. [link]. Accessed: 2026-07-10.

Sallie Sorenson. 2022. 10 Django Views Best Practices. [link]. Accessed: 2026-07-10.

Jair Vercosa. 2020. Django Model Guideline. [link]. Accessed: 2026-07-10.
Publicado
11/09/2026
TEIXEIRA, Leopoldo; SILVA, Eduardo Luiz. Django-Specific Code Smells: Catalog, Prevalence, and Automated Detection. In: WORKSHOP DE VISUALIZAÇÃO, EVOLUÇÃO E MANUTENÇÃO DE SOFTWARE (VEM), 14. , 2026, São Paulo/SP. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2026 . p. 179-183. DOI: https://doi.org/10.5753/vem.2026.32893.