zoukankan      html  css  js  c++  java
  • Sanic框架安装与简单用法

    ###

    sanic官方文档:https://sanic.readthedocs.io/en/latest/

    ###

    看看官方文档的介绍

    Sanic is a Python 3.7+ web server and web framework that’s written to go fast.

    It allows the usage of the async/await syntax added in Python 3.5, which makes your code non-blocking and speedy.

    ###

    Sanic是一个类似Flask的Python 3.7+ Web服务器,它的写入速度非常快。除了Flask之外,Sanic还支持异步请求处理程序。这意味着你可以使用Python 3.5中新的闪亮的异步/等待语法,使你的代码非阻塞和快速。

    Sanic最低支持Python 3.7,如果需要学习Sanic,请先下载版本不低于3.7的Python包

    ###

    安装Sanic

    pip3 install sanic

    注意:Sanic暂时只能在mac os系统和linux系统下安装,windows系统暂不支持

    ###

    一个简单的Sanic小程序

    Hello World Example

    from sanic import Sanic
    from sanic.response import json
    
    app = Sanic("My Hello, world app")
    
    @app.route('/')
    async def test(request):
        return json({'hello': 'world'})
    
    if __name__ == '__main__':
        app.run()

    运行manager.py文件,就可以运行起来一个简单的由Sanic开发web小程序了,我们可以在浏览器输入http://localhost:5000/就可以访问了!

    用惯Flask的同学,会发现Sanic的用法与Flask有点类似,

    ####

    ####

  • 相关阅读:
    【Coreforces 1253E】
    计数专题乱做
    PKUWC2020乱做
    多项式板子
    notepad
    2021.4.9
    2021.4.8
    2021.3.31
    2021.3.26
    2021.3.25
  • 原文地址:https://www.cnblogs.com/andy0816/p/15591535.html
Copyright © 2011-2022 走看看