玩了一下午的 tornado,提几个问题

2015-02-02 19:10:53 +08:00
 cevincheung
"""
自定义错误页面
"""
class errorController(userController):
    def get(self):
        self.write('404 not found');
    def post(self):
        errorController.get(self);

怎么实现类型这样的效果:

"""
自定义错误页面
"""
class errorController(userController):
    def get(self):
    def post(self):
    def delete(self):
    # options put ......
        self.write('404 not found/ method not allowed');

然后是关于class继承

class a():
    def __init__():
        pass;

class b(a):
    def __init__():
        pass;

像php有parant::__init()__可以执行继承的class的同名方法。python捏?
还有就是像

class baseController(tornado.web.RequestHandler):
class userController(baseController):
class panelController(userController):
# 然后就莫名其妙500了……

然后是怎么动态加载一些python文件,比如:

a = 'a';
import a;
# 但是即便实现了好像也没用,python貌似所有执行过程中需要的文件都需要预先import……
# 像php   if($get[a]) include_once $get[a].php

暂时这么多……

2774 次点击
所在节点    Python
5 条回复
dddd
2015-02-02 19:15:27 +08:00
基础比我还差还是先放下 tornado 吧……
14
2015-02-02 19:44:40 +08:00
class b(a):
....def __init__(self):
........super(b).__init__(self)

a = __import__('a')
yetone
2015-02-02 20:42:27 +08:00
zhwei
2015-02-03 07:27:38 +08:00
1、

```python

class errorController(userController):
def get(self):
self.write('404 not found') # 没有分号

post = delete = get

```

2、楼上正解 `super()`
3、[importlib](https://docs.python.org/3/library/importlib.html)


PS. 这些跟Tornado没什么关系, 都是Python基础语法,初学Python并且想做web的话可以用些更轻量的框架。
zenliver
2015-02-03 10:11:07 +08:00
你还是先把基础搞好吧,,,

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/167677

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX