Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/angstwad/flask-form-macros
Jinja2/Flask macros used to generate form fields
https://github.com/angstwad/flask-form-macros
Last synced: 12 days ago
JSON representation
Jinja2/Flask macros used to generate form fields
- Host: GitHub
- URL: https://github.com/angstwad/flask-form-macros
- Owner: angstwad
- License: apache-2.0
- Created: 2014-08-11T20:15:34.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-21T02:19:16.000Z (about 10 years ago)
- Last Synced: 2024-08-01T22:54:33.189Z (3 months ago)
- Homepage:
- Size: 146 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
flask-form-macros
=================## What?
Flask macros are Jinja2 macros that are called like functions. These macros create form field boilerplate, and were intended to replace my use of WTForms in my projects.
## Use
First add this template filter into your application:
```
@app.template_filter()
def slugify(string):
return string.lower().replace(' ', '_')
```Place `form_field_macros.html` in your Flask templates folder, and import:
```
{% import "form_field_macros.html" as fields %}
```Then call:
```
{{ fields.TextField('My Field') }}
```This will render a field that looks like this:
```
My Field:
````**Horizontal forms** are for Bootstrap-compatible horizontal forms. You'll of course need to have a properly sourced Bootstrap project for this to work. These macros are only meant to support Bootstrap 2.3.2.
```
{{ fields.TextField('My Field', horizontal=True) }}
``````
My Field:
```## Okay, now what?
Essentially, you pass in either a) the macro arguments as specified in the macro signature, or b) you pass in HTML attributes as booleans or key/value pairs. So, if you want to have an HTML5 "email" field, with a value set, that is required:
```
{{ fields.Field('Email Field', type="email", value="Put a value here", required=True) }}
```## License
Apache 2.0