TurboGearsPython 的 Web 框架

联合创作 · 2023-09-20 22:05

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

https://asciinema.org/a/181221.png

安装 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

浏览 4
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报