我有一个抽象Page模型,它定义了一种页面类型的公共字段,然后我将其子类化以限制允许的子页面类型。我希望这个抽象模型的所有子类都默认使用template抽象模型中定义的,但似乎没有。
class BaseListing(Page):
empty_message = RichTextField()
intro = RichTextField()
template = 'listing.html'
class Meta:
abstract = True
class BlogListing(BaseListing):
subpage_types = ['BlogPost']
Run Code Online (Sandbox Code Playgroud)
我希望 wagtail 默认使用模型中定义的模板BaseListing,但它会寻找blog_listing.html模板,除非我像这样专门template在BlogListing模型上设置:
class BlogListing(BaseListing):
subpage_types = ['BlogPost']
template = 'listing.html'
Run Code Online (Sandbox Code Playgroud)
在抽象页面模型上定义一个get_template方法。通常, 的默认实现get_template将简单地返回self.template(反过来默认为从类名派生的文件名,给出您当前看到的行为)。
最常见的用途get_template是根据每个请求更改模板(例如,为经过身份验证的用户提供不同的模板);但是,如果您将其定义为返回固定模板名称,这将覆盖每个子类获取其自己的模板的标准行为。
| 归档时间: |
|
| 查看次数: |
138 次 |
| 最近记录: |