Conversation
|
+1, but can we name it just |
|
Ok. Django use |
|
+1 for including something like this in I want to use it for the static file handler refactor, and I'd rather not implement it again. However, I don't like the idea of creating a new instance for every incoming request. Couldn't this be implemented somehow using the same approach as Custom Routing Criteria and a |
|
There are two kinds of views organized in classes:
First way doesn't need any library change. Just add |
There was a problem hiding this comment.
So what's the profit?
- You still need to register routes by hand (not auto-discovered by router).
- The
MyViewclass is used not instance ofMyView, so no custom initialization could be done. This would lead to some "view factories" like:
def my_view_factory(*args, **kw):
return lambda request: MyView(request, *args, **kw)There was a problem hiding this comment.
People asked for "class based views like Django" many times.
Personally I prefer another style of views organizing like http://aiohttp.readthedocs.org/en/stable/web.html#using-plain-coroutines-and-classes-for-web-handlers you know.
- Views should not be autodiscovered (but you may use
'*'as method name). - Yes, in non-trivial cases user should use custom factories (just like for asyncio protocols). I don't want to make a mess adding clumsy initializers like django's
View.as_view()etc.
There was a problem hiding this comment.
ok, agree to 1.
2. looks like a next request after this one.
Anyway, I not sure which is worse -- to have "class based views like Django" in aiohttp.web or to let people reinvent the wheel themselfs...
There was a problem hiding this comment.
If people asked me the question I would try to explain why they don't need it
There was a problem hiding this comment.
The problem is in this line: https://github.com/KeepSafe/aiohttp/pull/684/files#diff-b41dc5c66bc19f22fe7cc77c002db02cR501
Without it people may do it themselves (while most of them not experienced enough to override __iter__ or __await__ properly).
|
Why is it not named |
|
|
|
|
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
I've added example for Class Based View.
It doesn't require any aiohttp code change for
async def/awaitapproach but one line change is needed for@coroutine/yield from` old style.Folks, do you think
BaseViewmatters to be included intoaiohttp.webitself?