Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Flask integration for the Fanstatic resource publishing system.

Project Description


Flask integration for the Fanstatic resource publishing system.


Fanstatic is a flexible system for managing the static resources (CSS and Javascript) used by your web application. This extension provides simple integration between Fanstatic and Flask.

Adding static resources to your application becomes as simple as installing them with pip:

pip install js.jquery

and need-ing them in your template:

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


To start using Flask-Fanstatic, import and initialize the extension for your Flask application:

from flask import Flask
from flask_fanstatic import Fanstatic

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

Then, in your base template, add the top and bottom resources to include them in your HTML:

  {{ }}


  {{ g.fanstatic.bottom }}

You can declare resource to include, by using the needs() helper to declare resources needed by your template:

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


The example above uses dashes to tell Jinja to strip the extra whitespace such as the newline after the expression. See the Jinja docs for more details:

Fanstatic will use the top and bottom helpers above to include the CSS or JavaScript resources need-ed automatically.

You can also need multiple resources:

{{ g.fanstatic.needs(
) }}

The needs() method takes any number of strings, in the form <module>:<resource>. You can alternatively import the resources from your code and require them like:

from js.jquery import jquery

def index():
  return render_template('index.html')

Application resources

Flask-Fanstatic also makes it easy to add your application’s own static files as Fanstatic resources.

You can use the resource() helper to declare a resource in your application’s 'static' folder:

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

To include the resource, just use its name to require it in your template:

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

You can also declare named groups of resources:

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

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

  # with the name of an internal resource:

  # with an inline resource:

Groups are included in the same way from the template:

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

Blueprint resources

Blueprints can also use Fanstatic in almost the same way as application resources. Start by initializing a Fanstatic() object for your blueprint, and declare its resources:

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

In the template, reference resources from the current blueprint as .<name>:

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

Or explicitly provide the name of a blueprint to include a resource from a specific blueprint:

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


0.2.0 (2014-01-04)

Support for Fanstatic 1.0

0.1.1 (2013-05-08)

  • fix for apps with a url prefix

0.1.0 (2012-11-19)

Initial release

Release History

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Flask-Fanstatic-0.2.0.tar.gz (5.2 kB) Copy SHA256 Checksum SHA256 Source Jan 4, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting