简体   繁体   English

Django-将queryset转换为html元素

[英]Django - convert queryset to html elements

Im using Bokeh library for visualizing data. 我正在使用Bokeh库来可视化数据。 Embeding Bokeh charts into web apps is possible via exporting <script> and <div> (inserting them in this comment as text also required using special strings - &lt and &gt) html components of visualization and inserting them in html template. 通过导出<script>和<div>(使用特殊字符串-&lt和&gt,还需要将它们作为文本插入此注释作为文本),将Bokeh图表嵌入到Web应用程序中是可行的。

I have these components in Django database. 我在Django数据库中有这些组件。

How to insert them into templates, so they will be treated as html elements? 如何将它们插入模板,以便将它们视为html元素? Now I get rendered everything as plain text, because output to template automatically converts tags <,> to &lt and &gt. 现在,我将所有内容呈现为纯文本格式,因为输出到模板会自动将标记<,>转换为&lt和&gt。

Thank you for help! 谢谢你的帮助!

If you have the html in a model field (django database) then in your view, you'd get them using a filter , passing the results to the context which is then passed to the template to be rendered. 如果您在模型字段(django数据库)中具有html,则在视图中,可以使用filter来获取它们,将结果传递到上下文, 然后传递到要呈现的模板

If you want to provide some more detail as to the model they are in I can provide a little more concrete advice. 如果您想提供有关模型的更多详细信息,我可以提供一些更具体的建议。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM