diff --git a/docs/sanic/class_based_views.rst b/docs/sanic/class_based_views.rst index 0170d734..db1e8b2b 100644 --- a/docs/sanic/class_based_views.rst +++ b/docs/sanic/class_based_views.rst @@ -28,14 +28,15 @@ using all these methods would look like the following. from sanic.views import HTTPMethodView from sanic.response import text - app = Sanic('some_name') + app = Sanic("class_views_example") class SimpleView(HTTPMethodView): def get(self, request): return text('I am get method') - def post(self, request): + # You can also use async syntax + async def post(self, request): return text('I am post method') def put(self, request): @@ -49,22 +50,6 @@ using all these methods would look like the following. app.add_route(SimpleView.as_view(), '/') -You can also use `async` syntax. - -.. code-block:: python - - from sanic import Sanic - from sanic.views import HTTPMethodView - from sanic.response import text - - app = Sanic('some_name') - - class SimpleAsyncView(HTTPMethodView): - - async def get(self, request): - return text('I am async get method') - - app.add_route(SimpleAsyncView.as_view(), '/') URL parameters -------------- @@ -154,7 +139,7 @@ lambda: from sanic.views import CompositionView from sanic.response import text - app = Sanic(__name__) + app = Sanic("composition_example") def get_handler(request): return text('I am a get method') diff --git a/docs/sanic/config.rst b/docs/sanic/config.rst index 8b700956..4c24ddc4 100644 --- a/docs/sanic/config.rst +++ b/docs/sanic/config.rst @@ -39,13 +39,13 @@ Any variables defined with the `SANIC_` prefix will be applied to the sanic conf .. code-block:: python - app = Sanic(load_env='MYAPP_') + app = Sanic(__name__, load_env='MYAPP_') Then the above variable would be `MYAPP_REQUEST_TIMEOUT`. If you want to disable loading from environment variables you can set it to `False` instead: .. code-block:: python - app = Sanic(load_env=False) + app = Sanic(__name__, load_env=False) From an Object ~~~~~~~~~~~~~~ diff --git a/docs/sanic/debug_mode.rst b/docs/sanic/debug_mode.rst index 2c79a6bf..6b5f2f6f 100644 --- a/docs/sanic/debug_mode.rst +++ b/docs/sanic/debug_mode.rst @@ -21,7 +21,7 @@ and the Automatic Reloader will be activated. from sanic import Sanic from sanic.response import json - app = Sanic() + app = Sanic(__name__) @app.route('/') async def hello_world(request): @@ -43,7 +43,7 @@ the ``auto_reload`` argument will activate or deactivate the Automatic Reloader. from sanic import Sanic from sanic.response import json - app = Sanic() + app = Sanic(__name__) @app.route('/') async def hello_world(request): diff --git a/docs/sanic/exceptions.rst b/docs/sanic/exceptions.rst index 0baaef8c..e3f91c84 100644 --- a/docs/sanic/exceptions.rst +++ b/docs/sanic/exceptions.rst @@ -59,7 +59,7 @@ You can also add an exception handler as such: async def server_error_handler(request, exception): return text("Oops, server error", status=500) - app = Sanic() + app = Sanic("error_handler_example") app.error_handler.add(Exception, server_error_handler) In some cases, you might want to add some more error handling @@ -77,7 +77,7 @@ can subclass Sanic's default error handler as such: # You custom error handling logic... return super().default(request, exception) - app = Sanic() + app = Sanic("custom_error_handler_example") app.error_handler = CustomErrorHandler() Useful exceptions diff --git a/docs/sanic/getting_started.rst b/docs/sanic/getting_started.rst index 861bb722..74ca32ff 100644 --- a/docs/sanic/getting_started.rst +++ b/docs/sanic/getting_started.rst @@ -37,7 +37,7 @@ You can also install Sanic from `conda-forge