fix one example and add one example (#1257)
This commit is contained in:
parent
f9b29fd7e7
commit
becbc5f9ef
|
@ -1,7 +1,5 @@
|
||||||
from sanic import Sanic
|
from sanic import Blueprint, Sanic
|
||||||
from sanic import Blueprint
|
from sanic.response import file, json
|
||||||
from sanic.response import json
|
|
||||||
|
|
||||||
|
|
||||||
app = Sanic(__name__)
|
app = Sanic(__name__)
|
||||||
blueprint = Blueprint('name', url_prefix='/my_blueprint')
|
blueprint = Blueprint('name', url_prefix='/my_blueprint')
|
||||||
|
@ -19,7 +17,12 @@ async def foo2(request):
|
||||||
return json({'msg': 'hi from blueprint2'})
|
return json({'msg': 'hi from blueprint2'})
|
||||||
|
|
||||||
|
|
||||||
@blueprint3.websocket('/foo')
|
@blueprint3.route('/foo')
|
||||||
|
async def index(request):
|
||||||
|
return await file('websocket.html')
|
||||||
|
|
||||||
|
|
||||||
|
@app.websocket('/feed')
|
||||||
async def foo3(request, ws):
|
async def foo3(request, ws):
|
||||||
while True:
|
while True:
|
||||||
data = 'hello!'
|
data = 'hello!'
|
||||||
|
|
42
examples/simple_async_view.py
Normal file
42
examples/simple_async_view.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
from sanic import Sanic
|
||||||
|
from sanic.views import HTTPMethodView
|
||||||
|
from sanic.response import text
|
||||||
|
|
||||||
|
app = Sanic('some_name')
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleView(HTTPMethodView):
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
return text('I am get method')
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleAsyncView(HTTPMethodView):
|
||||||
|
|
||||||
|
async def get(self, request):
|
||||||
|
return text('I am async get method')
|
||||||
|
|
||||||
|
async def post(self, request):
|
||||||
|
return text('I am async post method')
|
||||||
|
|
||||||
|
async def put(self, request):
|
||||||
|
return text('I am async put method')
|
||||||
|
|
||||||
|
|
||||||
|
app.add_route(SimpleView.as_view(), '/')
|
||||||
|
app.add_route(SimpleAsyncView.as_view(), '/async')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(host="0.0.0.0", port=8000, debug=True)
|
Loading…
Reference in New Issue
Block a user