对象在falcon中没有属性“API”错误

2024-04-26 09:45:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将python 2.7.6与falconweb框架一起使用,并尝试运行简单的helloworld程序。但是在运行这个示例时,它给出了以下错误。你知道吗?在

代码:

import falcon

class ThingsResource(object):
    def on_get(self, req, resp):
        """Handles GET requests"""
        resp.status = falcon.HTTP_200
        resp.body = 'Hello world!'

# falcon.API instances are callable WSGI apps
wsgi_app = api = falcon.API()

# Resources are represented by long-lived class instances
things = ThingsResource()

# things will handle all requests to the '/things' URL path
api.add_route('/hello', things)

错误:

^{pr2}$

Tags: instances程序框架api错误requestsrespare
1条回答
网友
1楼 · 发布于 2024-04-26 09:45:42

你的python文件是猎鹰.py因此,当您调用falcon.API()时,您在文件中调用了一个方法API(),而不是从真正的falcon模块调用的。在

只要重命名你的文件,它就会工作。在


有关更完整的解决方案,请参见:

Trying to import module with the same name as a built-in module causes an import error

You will want to read about Absolute and Relative Imports which addresses this very problem. Use:

from __future__ import absolute_import Using that, any unadorned package name will always refer to the top level package. You will then

need to use relative imports (from .email import ...) to access your own package.

相关问题 更多 >