Skip to content

Instantly share code, notes, and snippets.

@danielrichman
Created September 12, 2013 11:11
Show Gist options
  • Select an option

  • Save danielrichman/6535866 to your computer and use it in GitHub Desktop.

Select an option

Save danielrichman/6535866 to your computer and use it in GitHub Desktop.
python-raven (+flask) replacement for .htaccess+mod_ucam_webauth
import os
from os.path import dirname, realpath
from os.path import join as path_join
from flask import Flask
from flask.helpers import send_from_directory
from raven.flask_glue import AuthDecorator
app = Flask(__name__)
assert not app.has_static_folder
app.secret_key = os.urandom(16)
require_principal = ["djr61"]
auth_decorator = AuthDecorator(require_principal=users)
app.before_request(auth_decorator.before_request)
content_folder = realpath(path_join(dirname(__file__), 'content'))
@app.route("/<path:filename>")
def serve(filename):
return send_from_directory(content_folder, 'content', filename)
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment