TurboGears是为Python提供网页前端到后端整合的网站框架,让网站开发更加快速和容易。
安装pip:
$curl-O'https://bootstrap.pypa.io/get-pip.py'$pythonget-pip.py安装 Turbogears:
$pipinstallTurboGears2开发一个简单的TGweb应用:
fromwsgiref.simple_serverimportmake_serverfromtgimportMinimalApplicationConfiguratorfromtgimportexpose,TGController#RootControllerofourwebapp,inchargeofservingcontentfor/classRootController(TGController):@expose(content_type="text/plain")defindex(self):return'HelloWorld'#Configureanewminimalapplicationwithourrootcontroller.config=MinimalApplicationConfigurator()config.update_blueprint({'root_controller':RootController()})#Servethenewlyconfiguredwebapplication.print("Servingonport8080...")httpd=make_server('',8080,config.make_wsgi_app())httpd.serve_forever()使用命令 pythonwebapp.py 启动,并打开浏览器访问 https://localhost:8080/
安装指南:https://docs.turbogears.org/1.0/Install
评论