sanic 类视图
作者:互联网
from sanic import Sanic from sanic.response import json from sanic.websocket import WebSocketProtocol # app = Sanic("websocket_example") from sanic import Sanic from sanic.views import HTTPMethodView from sanic.response import text app = Sanic("class_views_example") class SimpleView(HTTPMethodView): def get(self, request): return text('I am get method') # You can also use async syntax async def post(self, request): return text('I am post method') def put(self, request): return text('I am put method') def patch(self, request): return text('I am patch method') def delete(self, request): return text('I am delete method') app.add_route(SimpleView.as_view(), '/') if __name__ == "__main__": app.run(host="0.0.0.0", port=8000, protocol=WebSocketProtocol)
from sanic import Sanic from sanic.response import json from sanic.websocket import WebSocketProtocol # app = Sanic("websocket_example") from sanic import Sanic from sanic.views import HTTPMethodView from sanic.response import text app = Sanic("class_views_example") class SimpleView(HTTPMethodView): def get(self, request): return text('I am get method') # You can also use async syntax async def post(self, request): return text('I am post method') def put(self, request): return text('I am put method') def patch(self, request): return text('I am patch method') def delete(self, request): return text('I am delete method') app.add_route(SimpleView.as_view(), '/') if __name__ == "__main__": app.run(host="0.0.0.0", port=8000, protocol=WebSocketProtocol)
标签:text,self,am,视图,sanic,import,method 来源: https://www.cnblogs.com/HHMLXL/p/14888900.html