django - 这种方法有什么超级之处?
问题描述
class PublisherDetail(DetailView):
model = Publisher
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
# Add in a QuerySet of all the books
context['book_list'] = Book.objects.all()
return context
解决方案
根据基本的 Python 继承规则,super().get_context_data(...)
应该是DetailView.get_context_data()
,但由于它没有被定义,它是从SingleObjectMixin
.
推荐阅读
- java - 尝试添加反应时出现 onGuildMessageReceived() 问题
- angular - 包含重复的“内容”项目。.net core angular 6 web app中assets文件夹中的.json文件
- ruby-on-rails - 如何仅使用状态码检查 Rails 中 API 的成功响应?
- python - 通过另一种策略引用一种策略
- c# - 在查询中过滤多个 Geo near 操作会发送错误
- javascript - 了解产量如何影响 JS 生成器中的返回值
- apache-spark - 如果不在列表中,如何替换值?
- excel - 从目录中已关闭的工作簿中获取单元格值 - 如何遍历所有现有文件?
- python - 使用 Pandas 进行聚合和分组
- r - 在同一个 geom_text 上使用 ggrepel 和 shadowtext