How to use api.add_resource to route in different files?

I have a routing table in apis.py using flask-restful like:

api.add_resource(sonarqube.SonarqubeHistory, '/sonarqube/<project_name>')
api.add_resource(project.ProjectFile, '/project/<sint:project_id>/file')
api.add_resource(redmine.RedmineFile, '/download', '/file/<int:file_id>')

The resource classes are in other modules like sonarqube.py, project.py, or redmine.py.

My question is: Is that possible to also move api.add_resource() into the other modules (For more structured code)? I tried simply move the statement and from apis import api, but since apis.py also do other works it will result circular import.

Is there an example for similar use cases?



Read more here: https://stackoverflow.com/questions/68463256/how-to-use-api-add-resource-to-route-in-different-files

Content Attribution

This content was originally published by Romulus Urakagi Ts'ai at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: