Stereo Stereo - 1 year ago 61
Python Question

Flask REST Blueprint not found

I am trying to split up my app that uses Flask, Blueprint and REST in different components. But I cannot get the api to work.

The structure is as follows:

\-> resources


from flask import Flask
from flask_restful import Api

from restml.resources import hello

app = Flask(__name__)


if __name__ == '__main__':


from flask_restful import Api, Resource, url_for
from flask import Blueprint

blueprint = Blueprint('hello', __name__)
api = Api()

class Hello(Resource):
def get(self):
return {
"hello world"

api.add_resource(Hello, '/api/hello', endpoint='hello')

When I run the the app everything starts but
fails to retrieve from the url

How should I adjust the files so that the REST api can be found?


After adding

import restml.resources.hello import blueprint

I get the following error

web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.5/site-packages/gunicorn/", line 557, in spawn_worker
web_1 | worker.init_process()
web_1 | File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/", line 126, in init_process
web_1 | self.load_wsgi()
web_1 | File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/", line 136, in load_wsgi
web_1 | self.wsgi =
web_1 | File "/usr/local/lib/python3.5/site-packages/gunicorn/app/", line 67, in wsgi
web_1 | self.callable = self.load()
web_1 | File "/usr/local/lib/python3.5/site-packages/gunicorn/app/", line 65, in load
web_1 | return self.load_wsgiapp()
web_1 | File "/usr/local/lib/python3.5/site-packages/gunicorn/app/", line 52, in load_wsgiapp
web_1 | return util.import_app(self.app_uri)
web_1 | File "/usr/local/lib/python3.5/site-packages/gunicorn/", line 357, in import_app
web_1 | __import__(module)
web_1 | File "/usr/src/app/restml/", line 4, in <module>
web_1 | from web.restml.resources.hello import blueprint
web_1 | ImportError: No module named 'web'

Answer Source

You need to import your restml/resources/ file in restml/

from restml/resources/ import blueprint

Should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download