Use Flask blueprints for modularisation, per Khushboo Vashi.

This commit is contained in:
Dave Page 2015-01-19 16:38:47 +00:00
parent ca6ef66b61
commit 2c1688e6f4
3 changed files with 13 additions and 10 deletions

View File

@ -10,9 +10,7 @@
##########################################################################
import logging
import os, sys
from flask import Flask
from time import time, ctime
# Configuration settings
import config
@ -59,6 +57,11 @@ def create_app(app_name=config.APP_NAME):
# Register all the modules
for m in config.MODULES:
app.register_module(__import__('%s.views' % m).module)
app.logger.debug('Loading module %s' % m)
module = __import__(m, globals(), locals(), ['views'], -1)
app.register_blueprint(module.views.blueprint)
app.logger.debug('URL map: %s' % app.url_map)
return app

View File

@ -9,6 +9,3 @@
#
##########################################################################
from flask import Module
module = Module(__name__, 'utils')

View File

@ -10,14 +10,17 @@
##########################################################################
import config
from utils import module
from flask import Blueprint
from time import time, ctime
# Initialise the module
blueprint = Blueprint('utils', __name__)
##########################################################################
# A test page
##########################################################################
@module.route("/test")
def index():
@blueprint.route("/test")
def test():
output = """
Today is <b>%s</b>
@ -31,6 +34,6 @@ Today is <b>%s</b>
##########################################################################
# A special URL used to "ping" the server
##########################################################################
@module.route("/ping")
@blueprint.route("/ping")
def ping():
return "PING"