Flask App Doesn't Recognize Flask_restful Resources
I'm trying to build an API with flask_restful, but I don't know how to connect classes that inherit from Resource, with the actual app. I have the following structure page �
Solution 1:
Probably there is a much clever way of doing this but for me, the solution would be to remove the decorator @api.resource
decorator at page/api/resources.py
and make the following changes at page/init.py
from flask import Flask
from page.config import Config1
def create_app(config_class=Config1):
app = Flask(__name__)
app.config.from_object(config_class)
return app
I would also move the run.py
inside the page
folder and rename it to app.py
according to Flask documentation. This app.py
should have your routes so change it to something like this:
from page import create_app
from page.api.resources import HelloWorld
from flask_restfull import api
app = create_app()
api = Api(app)
api.add_resource(HelloWorld, '/hello-world')
And to run it just type flask run
inside the page
folder.
Post a Comment for "Flask App Doesn't Recognize Flask_restful Resources"