html - 如何以良好的格式将数据放入html中
问题描述
我正在使用 Django,并且我有在 html 中使用的模型信息
我遇到的问题
<img src="{% static 'Bola/noticias_imagens/{{ noticia.noticia_imagem }}' %}"
如何使此代码工作?
同样,我有一个带有一些标签的文本,<p>
当<br>
我执行此代码时,它还会在网站中按字面意思显示标签 显示
{{ noticia.noticia_texto }}
的文本示例:
"Hello.<p>Goodbye</p>"
有没有办法解决它?
解决方案
第一个问题:
{% with 'Bola/noticias_imagens/'|add:noticia.noticia_imagem as image_static %}
<img src="{% static image_static %}">
{% endwith %}
第二个问题:
- 你可以用过滤器做到这一点
{{ noticia.noticia_texto | safe }}
- 你可以用标签来做
{% autoescape off %}{{ noticia.noticia_texto }}{% endautoescape %}
但是您必须了解自己在做什么,因为这不安全,并且可能会导致 HTML 注入攻击。
推荐阅读
- javascript - 找不到 Firebase Admin SDK 功能
- java - 不兼容的 jaxb 依赖项
- python - GitPython 拉取特定目录
- excel - 完全匹配的条件格式公式
- python-3.x - 在熊猫中连接数据框后获取值不匹配的行位置
- javascript - 无法从本地域 URL 的文件中获取 JSON 数据(Django 静态文件)
- bash - 在 ubuntu 机器中重命名命令用于重命名一组文件
- sql-server - 如何将 Django 项目与 MS SQL 服务器连接起来?
- r - 对自身具有反应性的闪亮 rhandsontable
- rxjs - Angular 6 避免回调地狱