Browse Source

change structure, use blueprint for managing multiple app

weichen 4 years ago
parent
commit
d8595203dc
4 changed files with 25 additions and 16 deletions
  1. 12 2
      backstage/__init__.py
  2. 9 0
      backstage/editor/routes.py
  3. 0 13
      backstage/routes.py
  4. 4 1
      run.py

+ 12 - 2
backstage/__init__.py

@@ -1,6 +1,16 @@
 from flask import Flask
+import os
 
 
-app = Flask(__name__)
+def create_app():
+    SECRET_KEY = os.urandom(32)
+    app = Flask(__name__)
+    app.config['SECRET_KEY'] = SECRET_KEY
 
-from backstage import routes
+    from backstage.collections.routes import collections_app
+    from backstage.editor.routes import editor_app
+
+    app.register_blueprint(collections_app)
+    app.register_blueprint(editor_app)
+
+    return app

+ 9 - 0
backstage/editor/routes.py

@@ -0,0 +1,9 @@
+from flask import render_template, Blueprint
+
+
+editor_app = Blueprint('editor', __name__)
+
+
+@editor_app.route('/backstage/editor')
+def editor():
+    return render_template('editor.html', title='Type Editor', url='/collection/doll_and_drum_set')

+ 0 - 13
backstage/routes.py

@@ -1,13 +0,0 @@
-from flask import render_template, url_for
-from backstage import app
-
-
-@app.route('/backstage')
-@app.route('/backstage/home')
-def home():
-    return render_template('home.html')
-
-
-@app.route('/backstage/editor')
-def editor():
-    return render_template('editor.html', title='Type Editor', url='/collection/doll_and_drum_set')

+ 4 - 1
run.py

@@ -1,4 +1,7 @@
-from backstage import app
+from backstage import create_app
+
+
+app = create_app()
 
 
 if __name__ == '__main__':