Permalink
Browse files

blueprints redux

  • Loading branch information...
mjhea0 committed Sep 19, 2014
1 parent 63df159 commit 3e2b2a51df3e6000f9a8b4db99017c2900b3a5e1
View
@@ -1,4 +1,4 @@
from app import db
from project import db
# from models import BlogPost
# create the database and the db table
View
@@ -1,5 +1,5 @@
from app import db
from models import User
from project import db
from project.models import User
# insert data
# db.session.add(User("michael", "michael@realpython.com", "i'll-never-tell"))
View
@@ -2,7 +2,7 @@
from flask.ext.migrate import Migrate, MigrateCommand
import os
from app import app, db
from project import app, db
app.config.from_object(os.environ['APP_SETTINGS'])
migrate = Migrate(app, db)
View
@@ -0,0 +1,24 @@
#################
#### imports ####
#################
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.bcrypt import Bcrypt
import os
################
#### config ####
################
app = Flask(__name__)
bcrypt = Bcrypt(app)
app.config.from_object(os.environ['APP_SETTINGS'])
db = SQLAlchemy(app)
from project.users.views import users_blueprint
from project.home.views import home_blueprint
# register our blueprints
app.register_blueprint(users_blueprint)
app.register_blueprint(home_blueprint)
View
No changes.
File renamed without changes.
File renamed without changes.
@@ -2,24 +2,20 @@
#### imports ####
#################
from flask import Flask, flash, redirect, session, url_for, render_template
from flask.ext.sqlalchemy import SQLAlchemy
from project import db
from project.models import BlogPost
from flask import flash, redirect, session, url_for, render_template, Blueprint
from functools import wraps
import os
################
#### config ####
################
app = Flask(__name__)
app.config.from_object(os.environ['APP_SETTINGS'])
db = SQLAlchemy(app)
home_blueprint = Blueprint(
'home', __name__,
template_folder='templates'
)
from models import *
from project.users.views import users_blueprint
# register our blueprints
app.register_blueprint(users_blueprint)
##########################
#### helper functions ####
@@ -42,22 +38,14 @@ def wrap(*args, **kwargs):
################
# use decorators to link the function to a url
@app.route('/')
@home_blueprint.route('/')
@login_required
def home():
# return "Hello, World!" # return a string
posts = db.session.query(BlogPost).all()
return render_template('index.html', posts=posts) # render a template
@app.route('/welcome')
@home_blueprint.route('/welcome')
def welcome():
return render_template('welcome.html') # render a template
####################
#### run server ####
####################
if __name__ == '__main__':
app.run()
@@ -1,5 +1,5 @@
from app import db
from project.users.views import bcrypt
from project import db
from project import bcrypt
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -4,9 +4,6 @@
from flask import flash, redirect, render_template, request, \
session, url_for, Blueprint
from app import app
from flask.ext.bcrypt import Bcrypt
bcrypt = Bcrypt(app)
from functools import wraps
################
@@ -49,7 +46,7 @@ def login():
else:
session['logged_in'] = True
flash('You were logged in.')
return redirect(url_for('home'))
return redirect(url_for('home.home'))
return render_template('login.html', error=error)
@@ -58,4 +55,4 @@ def login():
def logout():
session.pop('logged_in', None)
flash('You were logged out.')
return redirect(url_for('welcome'))
return redirect(url_for('home.welcome'))
View
5 run.py
@@ -0,0 +1,5 @@
from project.app import app
if __name__ == '__main__':
app.run()
View
@@ -1,4 +1,4 @@
from app import app
from project import app
import unittest

0 comments on commit 3e2b2a5

Please sign in to comment.