GithubHelp home page GithubHelp logo

sgraaf / font-awesome-flask Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 793 KB

Font-Awesome-Flask is an extension for Flask that adds support for Font Awesome to your web application.

Home Page: https://font-awesome-flask.readthedocs.io/en/stable/

License: GNU General Public License v3.0

Python 92.49% HTML 7.51%
flask font-awesome jinja2 python

font-awesome-flask's Introduction

Font-Awesome-Flask

PyPI Supported Python Versions pre-commit.ci status Documentation Status PyPI - License

Font-Awesome-Flask is an extension for Flask that adds support for Font Awesome to your web application. It adds methods to load Font Awesome's resources (both Web Fonts + CSS and SVG + JS are supported) and render icons.

Installation

From PyPI

Font-Awesome-Flask is available on PyPI. Install with pip or your package manager of choice:

pip install Font-Awesome-Flask

From source

If you'd like, you can also install Font-Awesome-Flask from source (with flit):

git clone https://github.com/sgraaf/font-awesome-flask.git
cd font-awesome-flask
python3 -m pip install flit
flit install

Documentation

Check out the Font-Awesome-Flask documentation for the User's Guide and API Reference.

Example

Configuration

Font-Awesome-Flask can be configured via the Flask configuration API, using the config attribute of the Flask object. These are the available configuration values along with their description:

Configuration value Default Description
FONT_AWESOME_SERVE_LOCAL False Whether to serve Font Awesome's resources locally or from the CDN.

Initialization

Initialize the extension with the Flask application normally...:

from flask import Flask
from flask_font_awesome import FontAwesome

app = Flask(__name__)
font_awesome = FontAwesome(app)

... or using the Application Factory pattern:

from flask import Flask
from flask_font_awesome import FontAwesome

font_awesome = FontAwesome()


def create_app():
    app = Flask(__name__)
    font_awesome.init_app(app)
    return app

Loading resources

Font-Awesome-Flask provides three helper methods to load Font Awesome's resources: font_awesome.load(), font_awesome.load_js() and font_awesome.load_css().

Font Awesome can be used either via Web Fonts + CSS or via SVG + JS. Use the load_css() method for the former, and load_js() for the latter. You can also use the more general load(), which defaults to SVG + JS.

Whichever resource(s) you end up using, you can load them by including any of the load() methods in the head of your base template:

<head>
    ...
    {{ font_awesome.load_js() }}
    ...
</head>
<body>
    ...
</body>

Rendering icons

Font-Awesome-Flask provides two ways of rendering icons: via the font_awesome.render_icon() and font_awesome.render_stacked_icons() methods...:

{{font_awesome.render_icon("fas fa-house")}}
{{font_awesome.render_stacked_icons("fas fa-square", "fas fa-house")}}

... or via the Jinja macros of the same names:

{% from 'font_awesome.html' import render_icon, render_stacked_icons %}
{{ render_icon('fas fa-house') }}
{{ render_stacked_icons('fas fa-square', 'fasfa-house') }}

font-awesome-flask's People

Contributors

loelkes avatar sgraaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

loelkes

font-awesome-flask's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.