{ "info": { "author": "Chris Tabor", "author_email": "dxdstudio@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 2.7", "Topic :: Software Development" ], "description": "[](https://www.codacy.com/app/dxdstudio/flask_extras?utm_source=github.com&utm_medium=referral&utm_content=christabor/flask_extras&utm_campaign=badger)\n[](https://travis-ci.org/christabor/flask_extras)\n[](https://scrutinizer-ci.com/g/christabor/flask_extras/?branch=master)\n[](https://codeclimate.com/github/christabor/flask_extras)\n[](https://coveralls.io/github/christabor/flask_extras?branch=master)\n[](https://landscape.io/github/christabor/flask_extras/master)\n\n# Flask Extras\nAssorted useful flask views, blueprints, Jinja2 template filters, and templates/macros.\n\n## Overall setup\n\nAs of `3.4.0`, filters and templates will automatically be registered and available through the following simple command:\n\n```python\nfrom flask_extras import FlaskExtras\napp = Flask('myapp')\nFlaskExtras(app)\n```\n\nFor the old way, check out [this page](wiki/old_setup.md)\n\n## Available features\n\n### Views\n\nImport them like usual:\n\n```python\nfrom flask_extras.views import (\n statuses,\n)\n```\n\n*Note:* each view must have a valid template in your apps templates dir. See each view for the required names and locations.\n\n*Note:* each view has configuration helpers to inject or configure your app. See source for details.\n\n### Macros\n\n**Many more macros** are available. You can use them like so:\n\n```html\n{% from 'macros.html' import list_group, objects2table %}\n```\n\nFor 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).\n\nAlso, check the source and/or output to see what classes are available for style overrides.\n\n### Statuses\n\nProvides views for common status codes. Usage:\n\n```python\napp = statuses.inject_error_views(app)\n```\n\nSee source for more.\n\n### Decorators\n\nSee the source for more. Usage example:\n\n```python\nfrom flask_extras.decorators import require_headers\n\napp.route('/')\n@require_headers(['X-Foo'])\ndef foo():\n pass\n```\n\n\n### Forms\n\n#### WTForm Multi-step wizard\n\nA 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.\n\nUsage example:\n\n```python\nfrom flask.ext.wtf import FlaskForm\n\nfrom flask_extras.forms.wizard import MultiStepWizard\n\n\nclass MultiStepTest1(FlaskForm):\n field1 = StringField(validators=[validators.DataRequired()],)\n field2 = IntegerField(validators=[validators.DataRequired()],)\n\n\nclass MultiStepTest2(FlaskForm):\n field3 = StringField(validators=[validators.DataRequired()],)\n field4 = IntegerField(validators=[validators.DataRequired()],)\n\n\nclass MyCoolForm(MultiStepWizard):\n __forms__ = [\n MultiStepTest1,\n MultiStepTest2,\n ]\n```\n\nand an example route:\n\n```python\nfrom forms import MyCoolForm\n\n@app.route('/', methods=['GET', 'POST'])\ndef index():\n curr_step = request.args.get('curr_step')\n form_kwargs = dict(session_key='mycustomkey')\n if curr_step is not None:\n form_kwargs.update(curr_step=curr_step)\n form = forms.MyCoolForm(**form_kwargs)\n kwargs = dict(form=form)\n if request.method == 'POST':\n if form.validate_on_submit():\n if form.is_complete():\n data = form.alldata(combine_fields=True, flush_after=True)\n flash('Form validated and complete! data = {}'.format(data),\n 'success')\n return jsonify(data)\n else:\n flash('Great job, but not done yet ({} steps remain!).'.format(form.remaining))\n else:\n flash('Invalid form data.', 'error')\n return render_template('index.html', **kwargs)\n```\n\nand an example html page (using the [wtform_form](flask_extras/macros/macros.html) macro also available):\n\n```html\n{% if form.is_complete() %}\n Complete!\n{% else %}\n