简体   繁体   English

Wagtail - 如何使用不同的模板设置多个路径到相同的 model 实例?

[英]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?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django 中相同 model 的 UpdateView 的不同模板 - Different templates for UpdateView for the same model in Django Wigtail,我如何从不同的模型中填充ChoiceBlock中的选项? - Wagtail, how do I populate the choices in a ChoiceBlock from a different model? 一个 Wagtail 模型的多个 ModelAdmins - Multiple ModelAdmins for one Wagtail model 如何使Bottle能够搜索渲染模板的多个路径? - How to enable bottle to search multiple paths for rendering templates? 如何在 FastAPI 中定义多个路径不同但路径参数相同的 API 端点? - How to define multiple API endpoints in FastAPI with different paths but the same path parameter? 如何在同一张图上绘制来自不同模型的多条学习曲线? - How to plot multiple learning curve from different model on the same graph? python从具有相同方法名称的不同路径进行多重继承 - python multiple inheritance from different paths with same method name Django:几个路径,一个 ListView,不同的模板? - Django : Several paths, one ListView, different templates? 如何在 wagtail 管理员中修改页面 model 视图? - How to modify Page model view in wagtail admin? 如何在 Wagtail/Django 中对不同模型的查询集进行排序? - How to sort a queryset of different models in Wagtail/Django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM