I have a small rest application with the following structure
Basedir
- manage.py
- load_gen
- __init__.py
- app.py
- models.py
code snippet from manage.py
from load_gen import app, db
from load_gen.models import User
from flask.ext.script import Manager
manager = Manager(app)
if __name__ == '__main__':
manager.run()
code snippet from init.py
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db')
db = SQLAlchemy(app)
from load_gen import models
from load_gen import app
and finally app.py
from flask import Flask, jsonify, abort,make_response,url_for
from models import User
app = Flask(__name__)
tasks = [
{
'id': 1,
'title': u'Buy groceries',
'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
'done': False
}
]
def make_public_task(task):
new_task = {}
for field in task:
if field == 'id':
new_task['uri'] = url_for('get_task', task_id=task['id'], _external=True)
else:
new_task[field] = task[field]
return new_task
@app.route('/todo/api/v1.0/tasks', methods=['GET'])
def get_tasks():
return jsonify({'tasks': [make_public_task(task) for task in tasks]})
if __name__ == '__main__':
app.run(debug=True)
When I try to run this with python manage.py runserver, my app route is not registered and I keep getting 404 Not Found. url used - localhost:5000/todo/api/v1.0/tasks.
I have spent last 3 hours trying to figure out but am stuck. what am i doing wrong?