Django中的TinyMCE插件自定义标签

时间:2023-01-14 11:08:59

I am building a custom image insert plugin for TinyMCE. The idea is that each article already has a relationship with a collection of images through an ArticleImage model which allows the user to provide an article-specific caption. The TinyMCE will then insert a custom tag (something like <myapp:image image-id="9389" caption="Caption override">) which is rendered as a preview of the image and caption in the editor, and rendered into <figure><img src="images/9389.jpg" /><figcaption>Caption override (Photo: photographer)</figcaption></figure>. This could equally be something like <myapp:poll> or <myapp:video>.

我正在为TinyMCE构建一个自定义图像插入插件。这个想法是每篇文章已经通过ArticleImage模型与图像集合建立了关系,该模型允许用户提供特定于文章的标题。然后,TinyMCE将插入一个自定义标签(类似于 ),该标签在编辑器中呈现为图像和标题的预览,并呈现为

Django中的TinyMCE插件自定义标签
字幕覆盖(照片:摄影师) 。这可能类似于

My question is: what is the best way (and where is the best place) to parse this 'dummy tag' into its rendered HTML in the Django view?

我的问题是:在Django视图中将这个'虚拟标签'解析为其呈现的HTML的最佳方式(以及哪里是最佳位置)是什么?

Or is there another, better approach?

还是有另一种更好的方法吗?

1 个解决方案

#1


1  

IMHO, the best place to render custom markup, is in the template via a templatefilter.

恕我直言,渲染自定义标记的最佳位置,通过templatefilter在模板中。

I would risk myself to say that using a templatefilter to render custom markup is the "djangoish" way, since that's the way to go with django.contrib.markup.

我冒昧地说,使用templatefilter呈现自定义标记是“djangoish”方式,因为这是django.contrib.markup的方法。

Storing the custom tag in the model is a good idea, because then you can change the template filter implementation, which would be impossible if the custom tag is processed before storage.

将自定义标记存储在模型中是个好主意,因为这样您就可以更改模板过滤器实现,如果在存储之前处理自定义标记,则无法实现。

#1


1  

IMHO, the best place to render custom markup, is in the template via a templatefilter.

恕我直言,渲染自定义标记的最佳位置,通过templatefilter在模板中。

I would risk myself to say that using a templatefilter to render custom markup is the "djangoish" way, since that's the way to go with django.contrib.markup.

我冒昧地说,使用templatefilter呈现自定义标记是“djangoish”方式,因为这是django.contrib.markup的方法。

Storing the custom tag in the model is a good idea, because then you can change the template filter implementation, which would be impossible if the custom tag is processed before storage.

将自定义标记存储在模型中是个好主意,因为这样您就可以更改模板过滤器实现,如果在存储之前处理自定义标记,则无法实现。