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

Better warnings for mode

parent 1e95c424
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# app/__init__.py
import time
import copy
from termcolor import colored
import sys
from flask_api import FlaskAPI
from flask_sqlalchemy import SQLAlchemy
# local import
......@@ -24,10 +25,13 @@ 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 server in production mode.\
App will run in {} seconds".format(5-x))
sys.stdout.write(colored("\rYou are not running the server in production mode. " +
"App will run in {} seconds..".format(5-x), 'red'))
sys.stdout.flush()
time.sleep(1)
print(colored("\n\nRunning app in {} mode..".format(config_name), 'yellow'))
# This disables the HTML API renderer for flask_api when called through browsers.
if config_name == 'production':
application.config['DEFAULT_RENDERERS'] = [
......
from hodor.app import api
from flask_restplus import Resource
ns = api.namespace('/users', description='Operations related to blog posts')
@ns.route('/users')
class listusers(Resource):
def get(self):
return {'user': 'noob'}
api.add_resource(listusers, '/users')
\ No newline at end of file
from flask import Flask, request
from flask_restplus import Resource, Api
from api.user import ns as user_namespace
app = Flask(__name__)
api = Api(app)
todos = {}
@api.route('/<string:todo_id>')
class TodoSimple(Resource):
def get(self, todo_id):
return {todo_id: todos[todo_id]}
def put(self, todo_id):
todos[todo_id] = request.form['data']
return {todo_id: todos[todo_id]}
api.add_namespace(user_namespace)
if __name__ == '__main__':
app.run(debug=True)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment