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()
使用Pyramid框架构建小型应用
本文将指导您如何通过Pyramid框架实现一个简单的Web应用,包括配置路由、视图和WSGI应用。
8140

被折叠的 条评论
为什么被折叠?



