我开始使用Django进行个人博客构建,只需将django_summernote安装为编辑器。
但是,当我在html模板中获取文本时,主要文章的html标签是暴露的,无法正确应用。看起来像下面。
Here is the main text.
Hellow World! First Post <h1><span style="font-family: Arial;">Hello,
World!</span></h1><p><span style="font-family: Arial;">This is my first
post.</span></p><p><br></p>
下面的模板的地方。
<div id="middle_canvas">
Here is the main text. <br>
{% for post in recent_posts %}
{{ post.title }}
{{ post.text }} <br><br>
{% endfor %}
</div>
此外,Post模型如下所示。
class Post(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
我不知道在哪里检查。
答案 0 :(得分:0)
解决了我使用如下安全过滤器的问题。
{{post.title | safe}}