设置tornado.web.Application时出现问题

Imharjyotbagga

在龙卷风(python)中,我没有创建tornado.web.Application()的实例,而是尝试在使用init调用该类时对其进行更改

import tornado.web
import tornado.httpserver
import tornado.ioloop
import tornado.options
import os.path


from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("index.html", page_title="My Bookstore | HOME", header_text="Welcome to My Bookstore!")


class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r'/', MainHandler),
        ]
        settings = dict(
            template_path = os.path.join(os.path.dirname(__file__), "templates"),
            static_path = os.path.join(os.path.dirname(__file__), "static"),
            debug = True
        )
        tornado.web.Application(self, handlers, **settings)


if __name__ == "__main__":
    tornado.options.parse_command_line()
    #Note: not creating an instance of application here ('app'), just creating a list of handlers and a dict of settings and passing it to the superclass.
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()

但是我遇到这个错误,

Traceback (most recent call last):
  File "main.py", line 44, in <module>
    http_server = tornado.httpserver.HTTPServer(Application())
  File "main.py", line 27, in __init__
    tornado.web.Application(self, handlers, **settings)
  File "C:\Python\Python37\lib\site-packages\tornado\web.py", line 2065, in __init__
    handlers = list(handlers or [])
TypeError: 'Application' object is not iterable

有什么错误,我该如何解决?

伊恩·谢尔文顿

super初始化子类并想使用父类的子类时应调用__init__

这个

tornado.web.Application(self, handlers, **settings)

应该

super().__init__(handlers, **settings)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在CentOS中设置Web服务器时出现问题

来自分类Dev

设置DNS地址时出现问题

来自分类Dev

设置Shopizer时出现问题

来自分类Dev

启动Sikuli设置时出现问题

来自分类Dev

从Web API服务下载pdf文件时出现问题

来自分类Dev

在Spyder IDE中运行Web scraper时出现问题

来自分类Dev

从Web API服务下载pdf文件时出现问题

来自分类Dev

在Makefile中设置PATH时出现问题

来自分类Dev

设置Pubnub Nodejs服务器时出现问题

来自分类Dev

在JFrame中设置布局时出现问题

来自分类Dev

在iTunesConnect中设置“税收信息”时出现问题

来自分类Dev

设置用户空间LXC容器时出现问题

来自分类Dev

设置文本的垂直位置时出现问题

来自分类Dev

设置CKAN虚拟环境时出现问题

来自分类Dev

创建和设置Scala项目时出现问题

来自分类Dev

设置python 3.7虚拟环境时出现问题

来自分类Dev

在Windows 10 Home上设置KUBECTL时出现问题

来自分类Dev

条带:在订阅上设置关联帐户时出现问题

来自分类Dev

使用onclick设置tagName属性时出现问题

来自分类Dev

设置用户空间LXC容器时出现问题

来自分类Dev

设置iptables时出现问题(LDAP流量被阻止)

来自分类Dev

用烧瓶设置Chartkick时出现问题

来自分类Dev

在14.04.1安装上设置Thunderbird时出现问题

来自分类Dev

在CNAME上设置HTTPS时出现问题

来自分类Dev

设置显示为阻止时孩子出现问题

来自分类Dev

设置JAVA_HOME变量时出现问题

来自分类Dev

在设置Chrome起始页时出现问题

来自分类Dev

设置CKAN虚拟环境时出现问题

来自分类Dev

设置新的 Angular 站点时出现问题