You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from myapp import registry
from flask_rebar import ResponseSchema
from marshmallow import fields
class TodoSchema(ResponseSchema):
id = fields.Integer()
@registry.handles(
rule='/todos/<id>',
method='GET',
response_body_schema=TodoSchema() # for versions <= 1.7.0, use marshal_schema
)
def get_todo(id):
return {'id': id}
app.py
from myapp import create_app
app = create_app()
if __name__ == '__main__':
app.run()
The path /todos/<id> does not get registered.
Workaround (?)
So this is clearly some sort of import issue. I have tried creating the registry in various places but I wasn't having much luck. A weird workaround is to re-import the registry inside create_app:
from flask import Flask
from flask_rebar import Rebar
rebar = Rebar()
registry = rebar.create_handler_registry()
def create_app():
app = Flask(__name__)
from myapp.example.endpoints import registry # important to import it BEFORE initialising rebar with the app
rebar.init_app(app)
return app
This is a nasty solution - not actually sure why it works - I need to follow up the import order to figure out exactly what is going on. Would you have to import multuple times if you had more modules (i.e.: if there was an example2 module) ?
The text was updated successfully, but these errors were encountered:
Okay, it seems you could do from myapp.example.endpoints import get_todo instead, which then makes it similar to how you register views with Flask (see here)
I guess that isn't too bad. However, the fact that you have to do it before calling init_app is undesired.
I wonder if you could replicate Flask's registration behaviour when using Blueprints to avoid this?
This is a really frustrating issue, briefly mentioned in #62 . When using the factory pattern to create an app, path registration does not work.
Consider this folder structure:
myapp/__init__.py
myapp/example/endpoints.py
app.py
The path
/todos/<id>
does not get registered.Workaround (?)
So this is clearly some sort of import issue. I have tried creating the registry in various places but I wasn't having much luck. A weird workaround is to re-import the
registry
insidecreate_app
:This is a nasty solution - not actually sure why it works - I need to follow up the import order to figure out exactly what is going on. Would you have to import multuple times if you had more modules (i.e.: if there was an
example2
module) ?The text was updated successfully, but these errors were encountered: