Pyramid

1.需要有工匠精神

金字塔

开始小,结束大

完工框架

有雄心壮志的项目起于小而终于大,必须坚持完成。

你需要一个支持你的决定的Python web框架,

由工匠为工匠。

2.Hello 的例子 图1 hello world

图1 hello world
#从wsgiref.simple.server 引入一个
#并且通过/ route到hello_work
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('Hello World!')

if __name__ == '__main__':
    with Configurator() as config:
        config.add_route('hello', '/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 6543, app)
    server.serve_forever()

与许多其他Python web框架一样,Pyramid使用WSGI协议将应用程序和web服务器连接在一起。

为了方便起见,本例中使用wsgiref服务器作为WSGI服务器,因为它是在Python标准库中提供的。

脚本从pyramid.config模块导入Configurator类。

配置器类的一个实例稍后将用于配置棱锥体应用程序。脚本还导入pyramid.response.response类以供以后使用。

此类的实例将用于创建web响应。

3.还有更大的界面等着

需要查看一下.jinja2的模板

发布了134 篇原创文章 · 获赞 12 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/keny88888/article/details/104011459