来自 Django 文档:
While your class is instantiated for each request dispatched to it, class attributes set through the as_view() entry point are configured only once at the time your URLs are imported.
考虑到高并发流量,按请求实例化 View 会不会效率低下?
最佳答案
除了 jpmc26 的评论外,我想这不是什么大问题。如果您遵循 Django 从收到请求到呈现响应的工作流程,那么会涉及更多启动对象的步骤。基于类的 View 可能是问题最少的,假设您没有将其实现为阻塞。
关于Django:为每个请求实例化基于类的 View ,效率高吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21719130/