diff --git a/docs/sanic/logging.md b/docs/sanic/logging.md index 0fd9c75c..7dc4660e 100644 --- a/docs/sanic/logging.md +++ b/docs/sanic/logging.md @@ -10,6 +10,7 @@ A simple example using default setting would be like this: ```python from sanic import Sanic from sanic.config import LOGGING +from sanic.response import text # The default logging handlers are ['accessStream', 'errorStream'] # but we change it to use other handlers here for demo purpose @@ -20,7 +21,7 @@ app = Sanic('test') @app.route('/') async def test(request): - return response.text('Hello World!') + return text('Hello World!') if __name__ == "__main__": app.run(log_config=LOGGING) diff --git a/docs/sanic/response.md b/docs/sanic/response.md index 12718ca1..2807355e 100644 --- a/docs/sanic/response.md +++ b/docs/sanic/response.md @@ -5,70 +5,70 @@ Use functions in `sanic.response` module to create responses. ## Plain Text ```python -from sanic import response +from sanic.response import text @app.route('/text') def handle_request(request): - return response.text('Hello world!') + return text('Hello world!') ``` ## HTML ```python -from sanic import response +from sanic.response import html @app.route('/html') def handle_request(request): - return response.html('

Hello world!

') + return html('

Hello world!

') ``` ## JSON ```python -from sanic import response +from sanic.response import json @app.route('/json') def handle_request(request): - return response.json({'message': 'Hello world!'}) + return json({'message': 'Hello world!'}) ``` ## File ```python -from sanic import response +from sanic.response import file @app.route('/file') async def handle_request(request): - return await response.file('/srv/www/whatever.png') + return await file('/srv/www/whatever.png') ``` ## Streaming ```python -from sanic import response +from sanic.response import stream @app.route("/streaming") async def index(request): async def streaming_fn(response): response.write('foo') response.write('bar') - return response.stream(streaming_fn, content_type='text/plain') + return stream(streaming_fn, content_type='text/plain') ``` ## Redirect ```python -from sanic import response +from sanic.response import redirect @app.route('/redirect') def handle_request(request): - return response.redirect('/json') + return redirect('/json') ``` ## Raw @@ -76,12 +76,12 @@ def handle_request(request): Response without encoding the body ```python -from sanic import response +from sanic.response import raw @app.route('/raw') def handle_request(request): - return response.raw('raw data') + return raw('raw data') ``` ## Modify headers or status @@ -89,12 +89,12 @@ def handle_request(request): To modify headers or status code, pass the `headers` or `status` argument to those functions: ```python -from sanic import response +from sanic.response import json @app.route('/json') def handle_request(request): - return response.json( + return json( {'message': 'Hello world!'}, headers={'X-Served-By': 'sanic'}, status=200