Skip to main content

Assorted useful flask views, blueprints, Jinja2 template filters, and templates/macros

Project description

[![Build Status](https://travis-ci.org/christabor/flask_extras.svg?branch=master)](https://travis-ci.org/christabor/flask_extras)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/christabor/flask_extras/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/christabor/flask_extras/?branch=master)
[![Code Climate](https://codeclimate.com/github/christabor/flask_extras/badges/gpa.svg)](https://codeclimate.com/github/christabor/flask_extras)

# Flask Extras
Assorted useful flask views, blueprints, Jinja2 template filters, and templates/macros.

## Overall setup

~~Since the nature of macros and filters makes it harder to import as a standard package, the best way to use this project is as a git submodule. This can be done easily, just use `git submodule add https://github.com/christabor/flask_extras.git` inside your current git project. This allows easy updates.~~

This project has been converted a proper python package. You can use it easily in the same way as before, but without the headache of submodules.

## Testing

Run `nosetests .`

## Registering filters
It's easy. All filters are registered at once, using the following command:

```python
from flask_extras.filters import config as filter_conf

filter_conf.config_flask_filters(app)
```

## Using macros

The best way is to add the templates to your jinja instance, rather than having to move folders around after cloning the module.

This can be done using the following

### As a submodule:

```python
import os
import jinja2

extra_folders = jinja2.ChoiceLoader([
app.jinja_loader,
jinja2.FileSystemLoader('{}/flask_extras/macros/'.format(os.getcwd())),
])
app.jinja_loader = extra_folders
```

### As a package:

```python
import os
import jinja2

from flask_extras import macros as extra_macros

extra_folders = jinja2.ChoiceLoader([
app.jinja_loader,
jinja2.FileSystemLoader(os.path.dirname(extra_macros.__file__)),
])
app.jinja_loader = extra_folders
```

Which will load the default `templates` folder, and the new macros.

Now, just import them like any other macro:

```html
{% from 'macros.html' import list_group, objects2table %}
```

See [macros](macros.md) page for details.

## Using views

Import them like usual:

```python
from flask_extras.views import (
statuses,
)
```

*Note:* each view must have a valid template in your apps templates dir. See each view for the required names and locations.

*Note:* each view has configuration helpers to inject or configure your app. See source for details.

#### Statuses

Provides views for common status codes. Usage:
```python
app = statuses.inject_error_views(app)
```

Project details


Download files

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

Source Distribution

flask_extras-3.3.0.tar.gz (9.1 kB view details)

Uploaded Source

File details

Details for the file flask_extras-3.3.0.tar.gz.

File metadata

  • Download URL: flask_extras-3.3.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for flask_extras-3.3.0.tar.gz
Algorithm Hash digest
SHA256 019a5d9ff1cb9731974b0a0102a7f28ad0f6266b11e0d3853576f4a4c0148fee
MD5 7419f8bbdd097abcbd13d1f92b3f18be
BLAKE2b-256 e63b88c16e2828cc8e0f048e18cb7ac9d8c4d8162b9a009766fff6727f544aa7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page