Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FAQ #2471

Merged
merged 2 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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