Skip to main content

This extension provides basic template widget feature for Flask

Project description


This extension provides basic template widget feature for Flask

Installing Flask-Widgets

Install with **pip**:

pip install flask-widgets

Set Up

Widgets is managed through a "Widgets" instance:

from flask import Flask
from flask.ext.widgets import Widgets

app = Flask(__name__)

widgets = Widgets(app)

You may also set up your "Widgets" instance later at configuration
time using **init_app** method:

widgets = Widgets()

app = Flask(__name__)

Register Widgets

To register a single widget or a group of them, you will use the
"widget()" and "position()" decorators:

def title():
return 'Flask-Widget example'

@widgets.position('sidebar', order=1)
def sidebar_featured_items():
return dict(the='variables', go='here')

The example above will register a standalone widget named "title" and
position "sidebar"

To reorder the widgets in a position, adjust the "order" variable,
widget with less order will render first

Widget method must return a *dict* of variables or a string, in case
it returns a *dict*, "Widgets" with render them with a template has
same name as the method "widgets/sidebar_featured_items.html" You can
register as many positions and the number of widgets for them as you

Render Widgets in Template:

You will use template methods :meth`widget` and :meth`widgets` to
render widgets:

<!DOCTYPE html>
<title>{{ widget('title') }}</title>
<div style="border:1px solid #ccc">
{{ widgets('header') }}
Template body
<div style="border:1px solid #ddd">
{{ widgets('footer') }}

"Widgets" will render registered widgets for you, if you need


* The extension is in development, use it ask your own risk

* If you have better ideas or any suggestion please feel free to
contact me

* If you can improve this document, please help!

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
Flask_Widgets-0.1-py2.7.egg (3.4 kB) Copy SHA256 hash SHA256 Egg 2.7
Flask-Widgets-0.1.tar.gz (1.8 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page