https://github.com/kageurufu/flask-sandbox
A Flask plugin to restrict blueprints to specific users
https://github.com/kageurufu/flask-sandbox
Last synced: 3 months 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 (about 12 years ago)
- Default Branch: master
- Last Pushed: 2013-09-30T18:36:09.000Z (almost 12 years ago)
- Last Synced: 2025-04-11T22:47:33.582Z (3 months ago)
- Language: Python
- Size: 152 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
flask-sandbox
=============[](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("/"))