Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kageurufu/flask-sandbox
A Flask plugin to restrict blueprints to specific users
https://github.com/kageurufu/flask-sandbox
Last synced: 11 days ago
JSON representation
A Flask plugin to restrict blueprints to specific users
- Host: GitHub
- URL: https://github.com/kageurufu/flask-sandbox
- Owner: kageurufu
- License: gpl-3.0
- Created: 2013-07-15T16:44:16.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-30T18:36:09.000Z (about 11 years ago)
- Last Synced: 2024-09-24T19:43:00.726Z (about 2 months ago)
- Language: Python
- Size: 152 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
flask-sandbox
=============[![Build Status](https://travis-ci.org/kageurufu/flask-sandbox.png?branch=master)](https://travis-ci.org/kageurufu/flask-sandbox)
A Flask plugin to restrict blueprints to specific users, this depends on flask-login's current_user, so that is required
Goals of this extension are simple code, extendable code, and readability. So far, its only 31 lines of code
Usage
=====from flask import Flask, Blueprint, redirect
from flask.ext.login import LoginManager
from flask.ext.sandbox import Sandboxapp = Flask(__name__)
login_manager = LoginManager(app)
sandbox = Sandbox(app)@app.route("/protected/admin/page")
@sandbox(lambda user: user.admin)
def protected_admin_page():
return render_template("admin.jinja")blueprint = Blueprint("admin", __name__)
@blueprint.route("/admin")
def admin():
return render_template("admin.jinja")sandbox.register_blueprint(blueprint, lambda user: user.admin == True, redirect("/"))