用于定义独立于实际后端基础结构的基于烧瓶的后端页面的最小api

mara-page的Python项目详细描述


MARA页面

Build StatusPyPI - LicensePyPI versionSlack Status

用于独立于实际后端基础设施定义基于烧瓶的后端页面的最小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将呈现如下响应:

Example backend

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用jackson序列化/反序列化具有不同属性的子属性   javascript驱动程序。getTitle()从错误页面获取数据   java web应用程序的增量部署   java字符引用“&#x10”是无效的XML字符   java MyEclipse+Hibernate不按ID排序属性集?   找不到IBM Filenet P8更改预处理器Java实现   java比较器,用于按浮点参数对对象arraylist排序   java如何调试。来自eclipse或其他版本的bsh文件   不允许使用java rest api post方法   java如何在Servlet中打开弹出窗口,然后重定向页面   java的replaceAll方法对我不起作用我做错了什么?   我收到了javax。网ssl。SSLHandshakeException:握手期间远程主机关闭连接