Skip to content

Commit

Permalink
Update FAQ (#2471)
Browse files Browse the repository at this point in the history
* Update FAQ

* Mention aiohttp 2.3
  • Loading branch information
asvetlov authored Nov 7, 2017
1 parent 0b34a8f commit 2f3b9ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
31 changes: 23 additions & 8 deletions docs/faq.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
Frequently Asked Questions
==========================
FAQ
===

.. contents::
:local:

Are there any plans for @app.route decorator like in Flask?
-----------------------------------------------------------
There are couple issues here:

* This adds huge problem name "configuration as side effect of importing".
* Route matching is order specific, it is very hard to maintain import order.
* In semi large application better to have routes table defined in one place.
We have it already (*aiohttp>=2.3* required):
:ref:`aiohttp-web-alternative-routes-definition`.

The difference is: ``@app.route`` should have an ``app`` in module
global namespace, which makes *circular import hell* easy.

*aiohttp* provides a :class:`~aiohttp.web.RouteTableDef` decoupled
from an application instance::

routes = web.RouteTableDef()

@routes.get('/get')
async def handle_get(request):
...


@routes.post('/post')
async def handle_post(request):
...

For this reason feature will not be implemented. But if you really want to
use decorators just derive from web.Application and add desired method.
app.router.add_routes(routes)


Has aiohttp the Flask Blueprint or Django App concept?
Expand Down
3 changes: 3 additions & 0 deletions docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ viewed using the :meth:`UrlDispatcher.named_resources` method::
:meth:`UrlDispatcher.resources` instead of
:meth:`UrlDispatcher.named_routes` / :meth:`UrlDispatcher.routes`.


.. _aiohttp-web-alternative-routes-definition:

Alternative ways for registering routes
---------------------------------------

Expand Down

0 comments on commit 2f3b9ce

Please sign in to comment.