当前位置: 移动技术网 > IT编程>脚本编程>Python > [Python] How to use Pyramid?

[Python] How to use Pyramid?

2019年04月19日  | 移动技术网IT编程  | 我要评论

橡胶抛光轮,车恩杰,兄弟2820

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 https://localhost:8080')
    server.serve_forever()



如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网