Fanstic资源发布系统的烧瓶集成。

Flask-Fanstatic的Python项目详细描述


烧瓶风机

Fanstic资源发布系统的烧瓶集成。

http://www.fanstatic.org/

https://api.travis-ci.org/mgood/flask-fanstatic.png

概述

FAstatic是一种灵活的静态资源管理系统(CSS) javascript)由您的web应用程序使用。这个扩展提供了简单的 Fanstatic和烧瓶之间的集成。

向应用程序添加静态资源变得与安装它们一样简单 使用pip:

pip install js.jquery

以及need-在模板中使用它们:

{{ g.fanstatic.needs('js.jquery:jquery') }}

使用量

要开始使用flask fanstic,请导入并初始化 烧瓶应用:

from flask import Flask
from flask_fanstatic import Fanstatic

app = Flask(__name__)
fanstatic = Fanstatic(app)

然后,在基本模板中,添加topbottom资源以包括 它们在HTML中:

<head>
  {{ g.fanstatic.top }}
</head>

<body>
  ...content...

  {{ g.fanstatic.bottom }}
</body>

通过使用needs()helper声明 模板所需的资源:

{{- g.fanstatic.needs('js.jquery:jquery') -}}
{% extends 'layout.html' %}
...

注意

上面的例子使用破折号告诉jinja去掉多余的空格,比如 作为表达式后面的换行符。有关更多详细信息,请参见Jinja文档: http://jinja.pocoo.org/docs/templates/#whitespace-control

fanstatic将使用上面的topbottom帮助程序来包含css 或者javascript资源need-ed自动生成。

您还可以need多个资源:

{{ g.fanstatic.needs(
  'js.jquery:jquery',
  'js.handlebars:handlebars'
) }}

needs()方法接受任意数量的字符串,格式如下 <module>:<resource>。您也可以从 编码并要求如下:

from js.jquery import jquery

@app.route('/')
def index():
  jquery.need()
  return render_template('index.html')

应用程序资源

flask fanstic还可以方便地将应用程序自己的静态文件添加为 Fanstatic资源。

您可以使用resource()helper在 应用程序的'static'文件夹:

fanstatic.resource('js/app.js', name='app_js', depends=[jquery])

要包含资源,只需使用它的name在模板中要求它:

{{ g.fanstatic.needs('app_js') }}

您还可以声明命名的资源组:

from js.jquery import jquery
fanstatic.resource('css/app.js', name='app_js')

# there are 3 ways to specify a group resource item:
fanstatic.group('app_resources', [
  # with an imported resource:
  jquery,

  # with the name of an internal resource:
  'app_js',

  # with an inline resource:
  fanstatic.resource('css/app.css'),
])

以与模板相同的方式包含组:

{{ g.fanstatic.needs('app_resources') }}

蓝图资源

蓝图也可以像应用程序一样使用fanstatic 资源。从初始化蓝图的Fanstatic()对象开始, 并声明其资源:

bluep = Blueprint('bluep', __name__, static_folder='static')
fanstatic = Fanstatic(bluep)
fanstatic.resource('bluep.css', name='bluep_css')

在模板中,将当前蓝图中的资源引用为.<name>

{{ g.fanstatic.needs('.bluep_css') }}

或者显式提供蓝图的名称以包含 具体蓝图:

{{ g.fanstatic.needs('bluep.bluep_css') }}

更改

0.2.0(2014-01-04)

支持Fanstatic 1.0

0.1.1(2013-05-08)

  • 修复带有url前缀的应用程序

0.1.0(2012-11-19)

初始版本

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

推荐PyPI第三方库


热门话题
用于批量操作的java RESTful API分块响应   java读取在线存储的文本文件   在Java ME中将双精度舍入到小数点后5位   java查找一个数字的最接近因子   java更改JMenuBar的字体   java Kmeans聚类算法运行时间和复杂性   java是否可以阻止try catch返回null   java内容解析器指向具有正确URI的错误表   java Android Kotlin插装测试未被识别为插装测试   java TestNG@Dataprovider   在forloop和print语句中声明变量时发生java错误   java在Android Studio 3中设置JNI