Python 微型web框架:Morepath
Morepath是具有強大的能力的Python 微型web框架。Morepath是一個Python WSGI微型框架。他使用路由,但是是針對模型的路由。Morepath是一個模型驅動,靈活的框架,這使得它富有表達力。
import morepathclass App(morepath.App): pass
class Document(object): def init(self, id): self.id = id
@App.path(path='') class Root(object): pass
@App.path(path='documents/{id}', model=Document) def get_document(id): return Document(id) # query for doc
@App.html(model=Root) def hello_root(self, request): return '<a href="%s">Go to doc</a>' % request.link(Document('foo'))
@App.html(model=Document) def hello_doc(self, request): return '<p>Hello document: %s!</p>' % self.id
if name == 'main': config = morepath.setup() config.scan() config.commit() morepath.run(App())</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!