Custom flash system allowing custom keyword arguments for Flask.
Project description
flask-flashy
Alternative to flask's flash system which allows you to pass in keyword arguments.
How it works
Flask's default flash() method simply takes two strings and passes them into the session (the message and category, eg flash('Username Is In Use', 'warning')), which is then obtained and cleared by get_flashed_messages() in jinja.
flask-flashy has a class-based flashing system, allowing you to pass in as many keyword arguments as you'd like, while still keeping the default message and category to align with flask and allow for minimal edits to convert (eg flash('Username Is In Use. Login Instead?', 'warning', url=url_for('login'), timestamp=datetime.now() )).
Installation & Basic Usage
Install via pip:
pip install flask-flashy
After installing, wrap your Flask app with a Flashy(app), or call Flashy.init_app(app)
from flask import Flask
from flask_flashy import Flashy
app = Flask(__name__)
flashy = Flashy(app)
or to initialize later or use with blueprints:
from flask import Flask
from flask_flashy import Flashy
app = Flask(__name__)
flashy = Flashy()
flashy.init_app(app)
Examples
After initializing the app, simply call for a flash in a route, passing in the message, optionally a second string as a category (will default to 'message' if not provided), and as many custom keyword arguments as you'd like.
@app.route('/')
def index():
flashy.flash('Woah there partner!', 'danger', url='https://example.com/')
return render_template('index.html')
Then get the flashes in the template using jinja:
{% with messages = get_flashy_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
{% if message.url %}
<a href="{{ message.url }}"><li class="{{ message.category }}">{{ message.message }}</li></a>
{% else %}
<li class="{{ message.category }}">{{ message.message }}</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endwith %}
And style and use to your hearts content.
TODO
- Category sorting like vanilla flask
- Fun flask-like logo
- ???
Release History
- 0.1.0 - Initial release on pypi.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_flashy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flask_flashy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0643480306a2830c17684310013a1a5e23b5305dece2c6951c1a6ff5aca8a1ea
|
|
| MD5 |
24cbcc0eeb57614e4632685d78c5d5ed
|
|
| BLAKE2b-256 |
ede0350f9a94a795d13fd3bf7acc98639fa0b3210cd0bc1337cc9aa5526b2ead
|