1
The problem you describe β duplicated code β is one of many common problems addressed by refactoring. The refactoring action to apply here is called Extract Method.
For shared code, extract the common code to a separate function and call that function from all the different places that need it.
For shared template content, extract the common content to a separate template file and {% include β¦ %}
that template from all the different places that need it.
Source:stackexchange.com