Skip to content

Commit cf99ebc

Browse files
committed
Improve documentation for CBV
1 parent 9bd48a3 commit cf99ebc

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

docs/web.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ application developers can organize handlers in classes if they so wish::
188188
app.router.add_route('GET', '/greet/{name}', handler.handle_greeting)
189189

190190

191+
.. _aiohttp-web-class-based-views:
192+
191193
Class Based Views
192194
^^^^^^^^^^^^^^^^^
193195

docs/web_reference.rst

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,29 +1411,29 @@ In general the result may be any object derived from
14111411
View
14121412
^^^^
14131413

1414-
Base class for class based views. Implementations should derive from
1415-
:class:`View` and override methods for handling HTTP verbs like
1416-
``get()`` or ``post()``::
1414+
.. class:: View(request)
14171415

1418-
class MyView(View):
1416+
Inherited from :class:`AbstractView`.
14191417

1420-
async def get(self):
1421-
resp = await get_response(self.request)
1422-
return resp
1418+
Base class for class based views. Implementations should derive from
1419+
:class:`View` and override methods for handling HTTP verbs like
1420+
``get()`` or ``post()``::
14231421

1424-
async def post(self):
1425-
resp = await post_response(self.request)
1426-
return resp
1422+
class MyView(View):
14271423

1428-
app.router.add_route('*', '/view', MyView)
1424+
async def get(self):
1425+
resp = await get_response(self.request)
1426+
return resp
14291427

1430-
The view raises *405 Method Not allowed*
1431-
(:class:`HTTPMEthodNowAllowed`) if requested web verb is not
1432-
supported.
1428+
async def post(self):
1429+
resp = await post_response(self.request)
1430+
return resp
14331431

1434-
.. class:: View(request)
1432+
app.router.add_route('*', '/view', MyView)
14351433

1436-
Inherited from :class:`AbstractView`.
1434+
The view raises *405 Method Not allowed*
1435+
(:class:`HTTPMEthodNowAllowed`) if requested web verb is not
1436+
supported.
14371437

14381438
:param request: instance of :class:`Request` that has initiated a view
14391439
processing.
@@ -1448,6 +1448,8 @@ supported.
14481448
``get()``, ``head()``, ``options()``, ``patch()``, ``post()``,
14491449
``put()``, ``trace()``.
14501450

1451+
.. seealso:: :ref:`aiohttp-web-class-based-views`
1452+
14511453

14521454
Utilities
14531455
---------

0 commit comments

Comments
 (0)