Skip to Content
流畅的Python(第2版)
book

流畅的Python(第2版)

by Luciano Ramalho
April 2023
Intermediate to advanced
769 pages
25h 16m
Chinese
Posts & Telecom Press
Content preview from 流畅的Python(第2版)
继承:瑕瑜互见
389
14-4
django.views.generic.list
模块的 UML 类图。
base
模块中的 3 个类做了简化(参见图 14-3)。
ListView
是聚合类,既没有方法也没有属性
Django
用户来说,图
14-4
中最重要的类是
ListView
。这是一个聚合类(
aggregate class
),
没有一点儿代码(主体只有文档字符串)。实例化后,
ListView
对象有一个
object_list
例属性,模板通过迭代这个属性显示页面内容(通常是数据库查询返回的包含多个对象的
结果)。至于如何生成模板迭代的对象,全部交给
MultipleObjectMixin
来处理。这个混入
类还提供了复杂的分页逻辑,即在一个页面中显示部分结果,并通过链接指向更多页面。
假如你想创建一个渲染模板的视图,但是以
JSON
式生成一系列对象,这时就要用到
BaseListView
了。这个类将
View
MultipleObjectMixin
的功能结合在一起,剔除了烦琐
的模板机制,非常方便用户扩展。
Django
基于类的视图
API
为例说明多重继承比
Tkinter
合适
。尤其是,这样很容易看出
混入类的作用:每个混入类都有明确的作用,而且名称都以
...Mixin
结尾。
基于类的视图还没有被
Django
用户普遍接受
。许多人确实使用它们,但是作为不透明的
盒子,其用途有限。当需要实现新效果时,许多
Django
程序员并未尝试重用基于类的视
图和混入,而是继续编写包揽全部职责的视图函数。
学习如何利用以及如何扩展基于类的视图 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python高级编程(第2版)

Python高级编程(第2版)

Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Python贝叶斯分析(第2版)

Python贝叶斯分析(第2版)

Posts & Telecom Press, Osvaldo Martin
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9787115612366