Including Partials
Partials are reusable template fragments.
Examples:
- navbars
- footers
- alerts
- “card” components
Create a partial
templates/partials/_navbar.htmltemplates/partials/_navbar.html:
<nav>
<a href="{{ url_for('home') }}">Home</a>
<a href="{{ url_for('about') }}">About</a>
</nav><nav>
<a href="{{ url_for('home') }}">Home</a>
<a href="{{ url_for('about') }}">About</a>
</nav>Include it in another template
{% include "partials/_navbar.html" %}{% include "partials/_navbar.html" %}Where to use includes
- inside
base.htmlbase.htmlto share nav/footer - in pages to share repeated UI patterns
Tip: naming convention
Many teams prefix partials with __ (like _navbar.html_navbar.html) to signal “not a full page”.
Jinja doesn’t require it, but it helps humans.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
