app = Flask(__name__)

# App root folder
app_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))

# Load client ids from config files
client_secret = os.path.join(app_root, "client_secret_google.json")
app.config["GOOGLE_CLIENT_ID"] = json.loads(open(client_secret, "r").read())["web"]["client_id"]


# Configuration
# app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///catalog'
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config["SECRET_KEY"] = "super_secret_key"
app.config["CSRF_SECRET_KEY"] = "csfr_super_secret_key"
app.config["UPLOAD_FOLDER"] = os.path.join(app_root, "uploads")
app.config["ALLOWED_IMAGE_EXTENSIONS"] = set(["jpg", "jpeg", "png", "gif"])


# Connect to database and create database session
engine = create_engine("postgresql:///catalog")
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
db = DBSession()
# db = SQLAlchemy(app)


# Register HTTP error handlers
@app.errorhandler(404)
def page_not_found(e):
Example #2
0
# This Python file uses the following encoding: utf-8

from flask import Flask, render_template, request, session
from StockInfo import StockInfo
from flask_debugtoolbar import DebugToolbarExtension
from wtforms import Form, StringField, validators
from wtforms.csrf.session import SessionCSRF

app = Flask(__name__)
# configure your application before initializing any extensions
app.debug = True
app.config["SECRET_KEY"] = b"security"
app.config["CSRF_SECRET_KEY"] = b"pleasedonttellanyone"  # required for session cookies to work
app.config["DEBUG_TB_TEMPLATE_EDITOR_ENABLED"] = True
toolbar = DebugToolbarExtension(app)


class CSRFEnabledForm(Form):
    class Meta:
        csrf = True
        csrf_class = SessionCSRF
        csrf_secret = app.config["CSRF_SECRET_KEY"]

        @property
        def csrf_context(self):
            return session


@app.route("/")
def hello_world():
    return "Hello My blog!"