Create a variable manager in flask, enter values in python, and use values on the jinja template.
Project description
Flask Variable Manager
The Flask Variable Manager is a Flask extension that allows you to manage variables within your Flask application.
It provides an interface to set and get variables, and even render them in Jinja2 templates.
This can be useful when you need to share data across different parts of your application.
Installation
To install the Flask Variable Manager, you can use pip:
pip install flask-variable-manager
Usage
First, import the VariableManagerExtension
from the flask_variable_manager
package:
Then, create an instance of the VariableManagerExtension
and initialize it with your Flask application:
from flask import Flask
from flask_variable_manager import VariableManagerExtension
vm = VariableManagerExtension()
app = Flask(__name__)
vm.init_app(app)
Now, you can use the VariableManagerExtension
to set and get variables in your Flask routes.
vm._local['my_var'] = 'Hello, World!'
vm._local['my_var']
Routes
Render a string as a Jinja2 template
This route allows you to render a string as a Jinja2 template.
It accepts a POST request at the /vm/render
endpoint.
Set a user-defined variable
This route allows you to set a user-defined variable.
It accepts a POST request at the /vm/var
endpoint.
Get all user-defined variables
This route allows you to get all user-defined variables.
It accepts a GET request at the /vm/var
endpoint.
(or vm/vars
for the multiple count of the variable)
Remove a user-defined variable
This route allows you to remove a user-defined variable.
It accepts a DELETE request at the /vm/var
endpoint.
(or vm/vars
for the multiple count of the variable)
Run a Python script and return the result
This route allows you to run a Python script and return the result.
It accepts a POST request at the /py/runner
endpoint.
import platform
from flask import g
data = additionalProp + "-" + platform.platform()
g.local['saved_user_variable'] = data
return data
Check the list of packages
This route allows you to check the list of python packages.
It accepts a GET request at the /py/packages
endpoint.
install and uninstall a package
This route allows you to install and uninstall a python package.
It accepts a POST request at the /py/install
, /py/uninstall
endpoint.
License
This project is licensed under the terms of the MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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
Built Distribution
File details
Details for the file flask_variable_manager-0.4.1.tar.gz
.
File metadata
- Download URL: flask_variable_manager-0.4.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e4a0b00f6fc744e7484039a76b5ccc3a5b671d53b20302669dfaec193bf5100 |
|
MD5 | 1d479ee3d6e2b03fd2e0026d3a7dc9c2 |
|
BLAKE2b-256 | 5d4795d28bbba52651ac73af99800953a30fe9e915c81c5d366542ec4320cfd1 |
File details
Details for the file flask_variable_manager-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: flask_variable_manager-0.4.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db831fad94fd0d6a62ac8c61427f85c8d3daea4b82ae5b9d07edf44689f3a429 |
|
MD5 | f6f6d1b6a5513583dbc5c3dbb9338480 |
|
BLAKE2b-256 | 87fc9436678a8d1062dc56e4a42871e57d4573e7beddf9ed3fec6c4181f13b33 |