用于定义独立于实际后端基础结构的基于烧瓶的后端页面的最小api
mara-page的Python项目详细描述
MARA页面
用于独立于实际后端基础设施定义基于烧瓶的后端页面的最小api。
当一个web应用程序分布在许多独立的flask蓝图上时,可以使用这个库来添加
- 导航条目
- 页面标题
- 基于资源的acl保护
- 页面特定的css和js文件
无法访问全局布局或烧瓶应用程序。
该库提供了一个werkzeugResponse
类的下拉列表,其中包含了
后端可以用来呈现最终的HTML页面。
示例
这是一个显示当前时间的简单Web用户界面:
"""Clock UI"""importflaskfromawesome_clockimportclockfrommara_pageimportacl,navigation,response,bootstrap,_# The flask blueprint that handlesblueprint=flask.Blueprint('awesome_clock',__name__,url_prefix='/clock',static_folder='static')# Defines an ACL resource (needs to be handled by the application)acl_resource=acl.AclResource('Clock')defnavigation_entry():"""Defines a part of the navigation tree (needs to be handled by the application)"""returnnavigation.NavigationEntry(label='Awesome clock',icon='clock-o',description='Something that tells the time',children=[navigation.NavigationEntry(label='What time is it now?',uri_fn=lambda:flask.url_for('awesome_clock.clock_page',when='now'),icon='question-circle',description='Should be able to display the current time'),navigation.NavigationEntry(label='And now?',icon='refresh',description='For the impatient',uri_fn=lambda:flask.url_for('awesome_clock.clock_page',when='and-now'))])@blueprint.route('/<string:when>')@acl.require_permission(acl_resource)# Requires permission to the `'Clock'` resourcedefclock_page(when:str):"""Defines the `/clock` page"""returnresponse.Response(# The actual page content (can be also a call to `flask.render_template`# or anything else that produces a string)html=bootstrap.card(header_left=_.h1['What time is it now?'],body=[_.p['The current time is ',str(clock.what_time_is_it_now())],_.img(src=flask.url_for('awesome_clock.static',filename='cuckoo-clock.jpg'),style='max-width:100%')]),# The page titletitle='Awesome clock',# Action buttonsaction_buttons=[response.ActionButton('javascript:location.reload()','Refresh','Refresh clock','refresh'),response.ActionButton('javascript:location.reload()','Update','Refresh clock','clock-o')])
这取决于实际的flask应用程序来定义如何呈现这样的响应,以及如何处理acl资源和导航条目。 mara app将呈现如下响应: