Flask-Silk¶
Flask-Silk is small Flask extension. It adds silk icons to your Flask application or blueprint, or extension!
Silk is very awesome. It will be good for your Flask extensions. But if someone use many Flask extensions which contains silk icons, they will lose their storage space too much. They can solve the problem with Flask-Silk.
If you want to preview silk icons, visit Silk Icon Dictionary.
Note
Silk is licensed under Creative Commons Attribution 2.5 License or 3.0 License. Before using the icons, read the license.
Installation¶
Install via PyPI:
$ easy_install Flask-Silk
Or check out development version:
$ git clone git://github.com/sublee/flask-silk.git
How to Use¶
If you want to contain silk icons to your application, follow the below example:
from flask import Flask
from flask.ext.silk import Silk
app = Flask(__name__)
silk = Silk(app)
In your application, you can get an icon’s url by:
url_for('silkicon', filename='bug.png')
It also works with Flask blueprint:
from flask import Blueprint
from flask.ext.silk import Silk
blu = Blueprint(__name__, __name__)
silk = Silk(blu)
API¶
- class flask_silk.Silk(base, silk_path='/icons')¶
This small extension adds
silkicon()
to your Flask application:from flask import Flask from flask.ext.silk import Silk app = Flask(__name__) silk = Silk(app)
Or it works with your Flask blueprint:
from flask import Blueprint from flask.ext.silk import Silk blu = Blueprint(__name__, __name__) silk = Silk(blu)
Now the application or blueprint’s
/icons/<filaname>
is bound tosilkicon()
for serves a prepared silk icon.Also you can work with your own icon directory:
import os.path my_icons = os.path.join(silk.base.static_path, 'icons') my_icons2 = os.path.join(silk.base.static_path, 'other-icons') silk.register_icon_directory(my_icons) silk.register_icon_directory(my_icons2)
Silk finds the icon in the registered directories first. If the icon does not exist in any directories, Silk finds the prepared silk icon.
- Parameters
base – the flask application or blueprint.
silk_path – the path to serve silk icons. Defaults to
/icons
.
- flask_silk.send_silkicon(filename, directories=[])¶
Sends an icon. The icon is in a shared directory or specified directories. Here’s a simple examples of how to send an icon:
from flask.ext.silk import send_silkicon from myapplication import app my_icons = os.path.join(app.static_path, 'icons') my_icons2 = os.path.join(app.static_path, 'other-icons') @app.route('/static/icons/<filename>') def icon(filename): return send_silkicon(filename, directories=[my_icons, my_icons2])
- Parameters
filename – the filename for icon.
directories – specified icon directories.