的get_context_data类对象的属性的。
我PasswordContextMixin在django / contrib / auth / views.py中遇到
class PasswordContextMixin:
extra_context = None
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'title': self.title,
**(self.extra_context or {})
})
return context
Run Code Online (Sandbox Code Playgroud)
我感到困惑context = super().get_context_data(**kwargs),因为它等于context = object.get_context_data(**kwargs)
In [15]: getattr(object, 'get_context_data')
AttributeError: type object 'object' has no attribute 'get_context_data'
Run Code Online (Sandbox Code Playgroud)
如何理解呢?
顾名思义,此类是一个mixin。它旨在与视图类(特别是TemplateView的子类)一起使用,该类将定义get_context_data。
| 归档时间: |
|
| 查看次数: |
106 次 |
| 最近记录: |