我正在使用 Flask 和 Flask-Restful 开发一个项目,试图根据用户在我的 Restful API 中的输入获取动态 url。我创建了一个带有 get 方法的类,该方法将响应请求,当用户调用另一个资源时,它会激活新资源并创建一个 url。
当我尝试向我的 api 添加一个新资源时,问题就出现了,它调用 Flask 中的函数 setupmethod 来检查应用程序是否处于调试状态以及是否已经发出第一个请求。
if self.debug and self._got_first_request:
raise AssertionError('A setup function was called after the '
'first request was handled. This usually indicates a bug '
'in the application where a module was not imported '
'and decorators or other functionality was called too late.\n'
'To fix this make sure to import all your view modules, '
'database models and everything related at a central place '
'before the application starts serving requests.')
克服这个问题的一种简单方法是修改 Flask 中的 add_view 函数以避免这种行为。我首先想了解为什么在调用第一个请求后避免创建视图或在我的情况下创建资源之类的设置方法?