Views -> Blueprints

This commit is contained in:
Felipe Martín 2015-12-05 00:17:03 +01:00
parent 16c6cbceb6
commit 1c3eebb5ca
7 changed files with 36 additions and 18 deletions

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
import importlib
from flask import Flask
from . import conf
@ -7,5 +9,9 @@ app = Flask(__name__)
app.debug = conf.DEBUG
app.secret_key = conf.SECRET_KEY
# Import all views
from . import views
# Autoload enabled blueprints
for blueprint in conf.BLUEPRINTS:
module = importlib.import_module(
'.apps.{}'.format(blueprint),
package=__name__)
app.register_blueprint(getattr(module, blueprint))

View File

@ -1,14 +1,16 @@
# -*- coding: utf-8 -*-
from flask import render_template, request
from flask import Blueprint, render_template, request
from .. import app
@app.route('/blog/<int:year>/<int:month>/<int:day>/<slug>/')
blog = Blueprint('simple_page', __name__,)
@blog.route('/blog/<int:year>/<int:month>/<int:day>/<slug>/')
def blog_post(year, month, day, slug):
return render_template('blog/post.html', **locals())
@app.route('/blog/')
@blog.route('/blog/')
def blog_list():
context = {
'page': request.args.get('page', 1)

11
fmartingrcom/apps/home.py Normal file
View File

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
from flask import Blueprint, render_template
home = Blueprint('home', __name__)
@home.route('/')
def homepage():
return render_template('home.html')

View File

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
from flask import render_template
from flask import Blueprint, render_template
from .. import app
@app.route('/projects/')
portfolio = Blueprint('portfolio', __name__)
@portfolio.route('/projects/')
def portfolio_list():
context = {}
return render_template('portfolio.html', **context)

View File

@ -9,6 +9,13 @@ SECRET_KEY = '0123456789'
# Database URI
DATABASE_URI = 'sqlite:////tmp/fmartingrcom.db'
# Enabled blueprints
BLUEPRINTS = (
'home',
'blog',
'portfolio',
)
# Try to import local_settings module for this enviroment
try:
from local_settings import *

View File

@ -1,9 +0,0 @@
# -*- coding: utf-8 -*-
from flask import render_template
from .. import app
@app.route('/')
def home():
return render_template('home.html')