You have a circular import; when the line from resource.HelloWorld import HelloWorld
executes, app
has not yet been assigned to, so in Helloworld.py
the line from app import app
fails.
Either import HelloWorld
later:
from flask import Flask
from flask.ext import restful
app = Flask(__name__)
api = restful.Api(app)
from resource.HelloWorld import HelloWorld
api.add_resource(HelloWorld, '/')
if __name__ == '__main__':
app.run(debug=True)
or import just the app
module in HelloWorld.py
:
from flask.ext import restful
import app
class HelloWorld(restful.Resource):
def get(self):
return {'hello': 'world'}
and refer to app.app
within a function or method called at a later time.