Skip to content

Instantly share code, notes, and snippets.

@sh4nks
Last active December 25, 2015 20:59
Show Gist options
  • Save sh4nks/7039158 to your computer and use it in GitHub Desktop.
Save sh4nks/7039158 to your computer and use it in GitHub Desktop.
integrate flaskbb in another app
from flask import Flask
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
from flaskbb.user.models import User
from flaskbb import create_app as flaskbb
from flaskbb.configs.development import DevelopmentConfig as Config
from flask.ext.login import LoginManager
from flask.ext.sqlalchemy import SQLAlchemy
DEBUG = True
# If you do not use the same session key, it will not work!
SECRET_KEY = 'SecretKeyForSessionSigning'
SQLALCHEMY_DATABASE_URI = 'sqlite:////home/peter/Documents/Workspace/flaskbb_website' + '/' + \
Config.PROJECT + ".sqlite"
# create the "main app"
app = Flask(__name__)
app.config.from_object(__name__)
# You need to initialize these applications in order to use it in this app
# You also need to add the configurations for extensions
# Update the flaskbb config
Config.SQLALCHEMY_DATABASE_URI = SQLALCHEMY_DATABASE_URI
login_manager = LoginManager(app)
db = SQLAlchemy(app)
# Create the flaskbb app
Config.SQLALCHEMY_DATABASE_URI = SQLALCHEMY_DATABASE_URI
flaskbb = flaskbb(Config)
@login_manager.user_loader
def load_user(id):
return User.query.get(id)
@app.route("/")
def index():
return "Hello World %s" % User.query.filter_by(id=1).first().username
application = DispatcherMiddleware(app, {
'/forum': flaskbb
})
if __name__ == "__main__":
run_simple(
'0.0.0.0',
5000,
application,
use_reloader=True,
use_debugger=True
)
# This will create the db from flaskbb
from flaskbb.utils.populate import create_test_data
from flaskbb.user.models import *
from flaskbb.forum.models import *
from flaskbb.pms.models import *
#from flaskbb.extensions import db
from app import flaskbb
with flaskbb.app_context():
create_test_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment