Skip to main content
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1f8f45e92a9b4ed1ab5029ee7a0e5534)](https://www.codacy.com/app/dxdstudio/flask_extras?utm_source=github.com&utm_medium=referral&utm_content=christabor/flask_extras&utm_campaign=badger)
[![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)
[![Coverage Status](https://coveralls.io/repos/github/christabor/flask_extras/badge.svg?branch=master)](https://coveralls.io/github/christabor/flask_extras?branch=master)
[![Code Health](https://landscape.io/github/christabor/flask_extras/master/landscape.svg?style=flat)](https://landscape.io/github/christabor/flask_extras/master)

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

## Overall setup

As of `3.4.0`, filters and templates will automatically be registered and available through the following simple command:

```python
from flask_extras import FlaskExtras
app = Flask('myapp')
FlaskExtras(app)
```

For the old way, check out [this page](wiki/old_setup.md)

## Available features

### 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.

### Macros

**Many more macros** are available. You can use them like so:

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

For the most comprehensive docs, check out each [macro](flask_extras/macros/). Comment "docstrings" are inline using jinja2 comments (these are not rendered in your html).

Also, check the source and/or output to see what classes are available for style overrides.

### Statuses

Provides views for common status codes. Usage:

```python
app = statuses.inject_error_views(app)
```

See source for more.

### Decorators

See the source for more. Usage example:

```python
from flask_extras.decorators import require_headers

app.route('/')
@require_headers(['X-Foo'])
def foo():
pass
```


### Forms

#### WTForm Multi-step wizard

A WTForm extension for handling an arbitrary number of separate forms as a single, multi-step, multi-POST wizard. All state and data are handled by apps' session backend. Building forms is just like you're used to -- simple and intuitive. Just inherit the `MultiStepWizard` class and put a `__forms__` key on it, which is just a list of all the forms you want to use. *Note*: list order matters for your form steps.

Usage example:

```python
from flask.ext.wtf import FlaskForm

from flask_extras.forms.wizard import MultiStepWizard


class MultiStepTest1(FlaskForm):
field1 = StringField(validators=[validators.DataRequired()],)
field2 = IntegerField(validators=[validators.DataRequired()],)


class MultiStepTest2(FlaskForm):
field3 = StringField(validators=[validators.DataRequired()],)
field4 = IntegerField(validators=[validators.DataRequired()],)


class MyCoolForm(MultiStepWizard):
__forms__ = [
MultiStepTest1,
MultiStepTest2,
]
```

and an example route:

```python
from forms import MyCoolForm

@app.route('/', methods=['GET', 'POST'])
def index():
curr_step = request.args.get('curr_step')
form_kwargs = dict(session_key='mycustomkey')
if curr_step is not None:
form_kwargs.update(curr_step=curr_step)
form = forms.MyCoolForm(**form_kwargs)
kwargs = dict(form=form)
if request.method == 'POST':
if form.validate_on_submit():
if form.is_complete():
data = form.alldata(combine_fields=True, flush_after=True)
flash('Form validated and complete! data = {}'.format(data),
'success')
return jsonify(data)
else:
flash('Great job, but not done yet ({} steps remain!).'.format(form.remaining))
else:
flash('Invalid form data.', 'error')
return render_template('index.html', **kwargs)
```

and an example html page (using the [wtform_form](flask_extras/macros/macros.html) macro also available):

```html
{% if form.is_complete() %}
<span class="well">Complete!</span>
{% else %}
<ul class="list-inline">
{% for step in form.steps %}
<li>
{% if step == form.curr_step %}
<strong class="lead label label-info">current {{ step }}</strong>
{% else %}
<a href="{{ url_for('app.index') }}?curr_step={{ step }}">{{ step }}</a>
{% endif %}
{% if not loop.last %}
&nbsp;&nbsp;/
{% endif %}
</li>
{% endfor %}
</ul>
{{ wtform_form(form,
classes=['form', 'form-horizontal'],
btn_classes=['btn btn-primary', 'btn-lg'],
align='right',
action=url_for('app.index'),
method='POST',
reset_btn=False,
horizontal=True,
) }}
{% endif %}
```

Metadata

Release files for flask_extras 4.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask_extras 4.0.3
File Size Uploaded
flask_extras-4.0.3.tar.gz 39.1 kB Details

Release files / flask_extras-4.0.3.tar.gz

Download URL flask_extras-4.0.3.tar.gz
Size 39.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0f8acd380f783cfea2c5d4d98dd2001ed9d0fdef743205a0c9e430e0ce107d12
BLAKE2b-256 checksum
How to use checksums
5904618b8074a79b572710287cc913d826205938e063cebe1ed7262e192a792d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

4.0.3 This release

1 release file

4.0.2

1 release file

4.0.1

1 release file

4.0.0

1 release file

3.6.2

1 release file

3.6.1

1 release file

3.4.0

1 release file

3.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page