我想创建一个博客。我想在管理面板中创建博客内容,并呈现与HTML格式的博客内容。
models.py
class Blog(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
date_created = models.DateField(auto_now_add=True)
def __str__(self):
return self.title在管理面板中:Create blog content with HTML format in admin
在模板中:
{% extends 'base.html' %}
{% block content %}
<h1>{{ blog.title }}</h1>
<p>{{ blog.content }}</p>
{% endblock content %}是否有任何模板标记、模型字段或其他内容来执行此操作?
发布于 2021-08-26 04:30:41
只需使用内置的safe模板标记就可以做到这一点。
在您的模板中:
{% extends 'base.html' %}
{% block content %}
<h1>{{ blog.title }}</h1>
<p>{{ blog.content | safe }}</p>
{% endblock content %}检查文档中是否有相同的here。
https://stackoverflow.com/questions/68932188
复制相似问题