-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Classbasedview #684
Classbasedview #684
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 |
app = Application(loop=loop) | ||
app.router.add_route('GET', '/', index) | ||
app.router.add_route('GET', '/get', MyView) | ||
app.router.add_route('POST', '/post', MyView) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what's the profit?
- You still need to register routes by hand (not auto-discovered by router).
- The
MyView
class 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people asked me the question I would try to explain why they don't need it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
/await
approach but one line change is needed for@coroutine
/yield from` old style.Folks, do you think
BaseView
matters to be included intoaiohttp.web
itself?