[英]Wagtail - how to setup multiple paths with different templates to the same model instaces?
Imagine a Page model:想象一个页面 model:
class ItemPage(Page):
featured = models.BooleanField(default=False)
priority = models.IntegerField(default=0)
This is model is served by Wagtail, on the url given by structure or the website (all instances are on the same place), for example:这是 model 由 Wagtail 提供服务,在结构或网站给出的 url 上(所有实例都在同一个地方),例如:
/items/1
/items/2
...
I would like to create a different path template, that would lead to the different template (same model, same data, different HTML/JS/CSS):我想创建一个不同的路径模板,这将导致不同的模板(相同的 model,相同的数据,不同的 HTML/JS/CSS):
/items-different-view/1
/items-different-view/2
...
I can use the Django mechanism for this - create a regex pattern in urls.py
that triggers a custom function that returns HTTP response (the other template filled with data of the particular instance).我可以为此使用 Django 机制 - 在
urls.py
中创建一个正则表达式模式,触发自定义 function ,返回 HTTP 响应的实例(另一个模板的特定数据填充)
But is there some more Wagtail way how to do it directly in the model without creation outlaying URLs and view function?但是还有更多 Wagtail 方法如何直接在 model 中进行操作,而无需创建外置 URL 并查看 function?
Override get_template()
on your Page
definition.在您的
Page
定义上覆盖get_template()
。 Reference:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.