Flask-Copilot

Installation

python -m pip install flask-copilot

Quickstart

  1. Initialize the Copilot extension on your Flask app.
  2. 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')
  1. 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.children %}
        <ul class="dropdown">{{ loop(entry.children) }}</ul>
      {% endif %}
    </li>
  {% endfor %}
</ul>

Contents:

API

The public API for Flask-Copilot.

Copilot

class flask_copilot.Copilot(app=None)[source]

The Flask-Copilot extension.

Parameters:app (Optional[flask.Flask]) – The application instance that this copilot should be registered to.
init_app(app)[source]

Register the extension with the application.

Parameters:app (flask.Flask) – The application to register with.
inject_context()[source]

Return a dict used for a template context.

register_entry(navbar_kwargs)[source]

Register a navbar entry with the copilot.

Parameters:navbar_kwargs (dict) – Arguments passed to the NavbarEntry instance.

Changelog

Version 0.1.0

Released 2016-02-21

  • Initial release

Indices and tables