# Circular Imports URL: /docs/troubleshooting/circular-imports/ Section: troubleshooting Tags: troubleshooting, circular import, macros -------------------------------------------------------------------------------- Circular Imports When using {% from "template.html" import macro_name %}, a template must not import from itself (directly or transitively). Kida detects this and raises TemplateRuntimeError with code K-TPL-003 instead of hitting Python's recursion limit. The Error TemplateRuntimeError: Circular import detected: 'showcase/_tab_content.html' imports itself (via showcase/_tab_content.html) Location: showcase/_tab_content.html:1 Code: K-TPL-003 Cause A template has {% from "X" import y %} where X is the same template or leads back to it: {# BAD: _tab_content.html imports from itself #} {% from "showcase/_tab_content.html" import tab_section %} {% def tab_section() %}content{% end %} Or transitive: A imports B, B imports A. Fix Split macros into a separate file and import from there: {# _tab_section.html — macros only #} {% def tab_section() %}content{% end %} {# _tab_content.html — imports from sibling #} {% from "showcase/_tab_section.html" import tab_section %} {% block tab_content %} {{ tab_section() }} {% end %} See Also Functions and macros — {% def %} and {% from %} render_block and def scope — Blocks do not inherit defs from the same template -------------------------------------------------------------------------------- Metadata: - Word Count: 171 - Reading Time: 1 minutes