TurboGears - Python 的 Web 框架


MIT
跨平台
Python

软件简介

TurboGears是为Python提供网页前端到后端整合的网站框架,让网站开发更加快速和容易。

安装 pip:

$ curl -O 'https://bootstrap.pypa.io/get-pip.py'
$ python get-pip.py

安装 Turbogears:

$ pip install TurboGears2

开发一个简单的 TG web 应用:

from wsgiref.simple_server import make_server
from tg import MinimalApplicationConfigurator
from tg import expose, TGController

# RootController of our web app, in charge of serving content for /
class RootController(TGController):
    @expose(content_type="text/plain")
    def index(self):
        return 'Hello World'

# Configure a new minimal application with our root controller.
config = MinimalApplicationConfigurator()
config.update_blueprint({
    'root_controller': RootController()
})

# Serve the newly configured web application.
print("Serving on port 8080...")
httpd = make_server('', 8080, config.make_wsgi_app())
httpd.serve_forever()

使用命令 python webapp.py 启动,并打开浏览器访问 http://localhost:8080/

安装指南:http://docs.turbogears.org/1.0/Install