用于定义独立于实际后端基础结构的基于烧瓶的后端页面的最小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在TextView中对齐部分文本   带有iText和eTPKCS11的java PKCS#11签名。dll&SunPKCS11提供程序   java Intellij Idea找不到jar   java Chrome/Firefox和Jetty HTTPS   java我无法打包找不到的JavaFX应用程序模块   多线程Java:排序从异步任务检索的结果   java客户端/服务器socket不能与外部连接一起工作   java如何在单击“下一步”按钮时获取其他详细信息?   java组织。springframework。网状物客户RestTemplate应声明为@Bean,而plain@Autowired抛出错误   java如何绘制javax。摆动将ImageIcon转换为JavaFX。fxml呈现用户界面?   使用for循环的Java跟踪   java如何编码字符串以显示彩色文本(基于字符串中的前缀)   Java保存/打开文件对象   基于java复选框的搜索:使用尽可能多的“”动态生成准备好的语句作为选中复选框的计数   java为什么crawler4j随机挂起?