您的位置:首页 > 编程语言 > Python开发

[Python] How to use Pyramid?

2014-03-04 11:59 344 查看
In this blog, i will tell you how to use Pyramid by codes.

'''
The start point is the Configurator class.Use it to configure the routes and views,
give application back to wsgi server finally.
The class Configurator inherits many classes.It is a big mix and has great power.
'''
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello(request):
return Response("This is my small application")
def page(request):
return Response("This is another page")
def main():
config = Configurator()
config.add_route('hello', '/')
config.add_route('test','/test')
config.add_route(name="page",pattern="/page",view=page)
config.scan('view')
config.add_view(view=hello,route_name="hello")

app = config.make_wsgi_app()
return app

if __name__ == '__main__':
app = main()
server = make_server('127.0.0.1', 8080, app)
print ('Starting up server on http://localhost:8080') server.serve_forever()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: