Quixote (web框架)
来自维基百科,自由的百科全书
Quixote是一個使用Python開發web應用的軟體框架。Quixote是「基於了簡單的、靈活的設計,使得可以快速的書寫應用,並受益於廣泛的可獲得的第三方Python模組。」[4]
Quixote應用典型的是個Python包,即組織入一個單一的目錄樹中的一組模組。Quixote接著對映一個URL至這個Python包內的一個函式或方法;接著用這個HTTP請求的內容來呼叫這個函式,並將結果返回給客戶端。
演示代碼
最小的Quixote演示程式。在安裝了quixote包之後,可以如下這樣執行它:$ python demo/mini_demo.py
。這個伺服器預設的監聽localhost:8080
。除錯和錯誤輸出會傳送到終端。
from quixote.publish import Publisher
from quixote.directory import Directory, export
class RootDirectory(Directory):
@export(name='')
def index(self):
return '''<html>
<body>Welcome to the Quixote demo. Here is a
<a href="hello">link</a>.
</body>
</html>
'''
@export
def hello(self):
return '<html><body>Hello world!</body></html>'
def create_publisher():
return Publisher(RootDirectory(),
display_exceptions='plain')
if __name__ == '__main__':
from quixote.server.simple_server import run
print('creating demo listening on http://localhost:8080/')
run(create_publisher, host='localhost', port=8080)
參見
參照
外部連結
Wikiwand - on
Seamless Wikipedia browsing. On steroids.