Skip to content
Snippets Groups Projects
Verified Commit 1e95c424 authored by Sachin Kamath's avatar Sachin Kamath
Browse files

Fixed bug in server run and warn user of running mode

parent 2848308a
Branches
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# app/__init__.py
import time
import copy
from flask_api import FlaskAPI
from flask_sqlalchemy import SQLAlchemy
# local import
......@@ -8,28 +10,30 @@ from instance.config import app_config
# initialize sql-alchemy
db = SQLAlchemy()
from hodor.models import *
from hodor.models import * # noqa
# TODO: Don't forget to change when in production
config_name = 'development'
def create_app(config_name):
app = FlaskAPI(__name__, instance_relative_config=True)
app.config.from_object(app_config[config_name])
app.config.from_pyfile('config.py')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
application = FlaskAPI(__name__, instance_relative_config=True)
application.config.from_object(app_config[config_name])
application.config.from_pyfile('config.py')
application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(application)
# Delay the application launch to get the user attention if running in testing mode
if config_name != 'production':
for x in range(0, 5):
print "*** YOU ARE NOT RUNNING THE APP IN PRODUCTION MODE!! *** CTRL + C TO ABORT. APP WILL RUN IN {} SECONDS".format(5-x)
print("You are not running the server in production mode.\
App will run in {} seconds".format(5-x))
time.sleep(1)
# This disables the HTML API renderer for flask_api when called through browsers.
if config_name == 'production':
app.config['DEFAULT_RENDERERS'] = [
application.config['DEFAULT_RENDERERS'] = [
'flask.ext.api.renderers.JSONRenderer',
]
return app
app = create_app('testing')
app = application
from hodor.controllers import *
from hodor.controllers import * # noqa
......@@ -10,5 +10,5 @@ def start():
@app.route('/print', methods=['GET', 'POST'])
def printer():
form = {'noob' : 'shit'}
form = {'hello': 'user'}
return form
# coding=utf-8
# -*- coding: utf-8 -*-
from hodor import db
class User(db.Model):
......
import os
from flask_script import Manager # class for handling a set of commands
from flask_migrate import Migrate, MigrateCommand
from hodor import db, create_app
from hodor.models.user import User
app = create_app(config_name='development')
......
......@@ -2,3 +2,4 @@ Flask
Flask-WTF
Jinja2
Flask-DebugToolbar
flask_api
#!/bin/env python
from hodor import app
config_name = 'development'
if __name__ == '__main__':
app.run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment