Flask-Copilot¶
Installation¶
python -m pip install flask-copilot
Quickstart¶
- Initialize the
Copilot
extension on your Flask app. - Add URL routes normally. Include
navbar_kwargs
to register routes to your navbar.
from flask import Flask
from flask_copilot import Copilot
app = Flask(__name__)
copilot = Copilot(app)
@app.route('/', navbar_kwargs={'path': 'Home'})
def index():
"""Render the home page."""
return render_template('index.html')
- Render your navbar using the
navbar
object automatically injected into your template context.
<ul>
{% for entry in navbar recursive %}
<li>
<a href="{{ entry.url() }}">
{{ entry.name }}
</a>
{% if entry.visible_children|list %}
<ul class="dropdown">{{ loop(entry.visible_children) }}</ul>
{% endif %}
</li>
{% endfor %}
</ul>
Contents: