Contributers guide¶
The WidgetServer class is used for serving Python functions as widgets or API endpoints.
-
class
dashboard.server.WidgetServer(widget_path, resolver=None, settings=None)[source]¶ Python framework for serving little widgets.
Widgets can be stored in
dashboard/widgets/.Any function ending with
_widgetwill be routed to/api/widgets/widget_name. For example,time_widgetis routed to/api/widgets/time.Widgets are loaded from
widget_path.An example widget looks like:
import datetime async def time_widget(request): return { "date": datetime.datetime.now().strftime("%A %B %d, %Y"), }
The widget can then be served as a JSON response or via HTML.
If HTML is requested, the returned JSON will be passed to the Jinja template (
$widget_path/templates/$widget_name.jinja.html) and rendered:<div>{{ date }}</div>
Static assets are served from
/static.