我已经安装了应用程序TinyMCE,所有程序都已启动并运行。但是有一个问题。发布带有图像的HTML输入时,将以纯文本显示。
<p><img src="https://www.djangoproject.com/s/img/logos/django-logo-negative.png" alt="django" /></p> <p>Lorem ipsum dolor sit amet, inani clita efficiantur sed et, ad honestatis complectitur vim.</p>
&#13;
的index.html:
{% for post in posts %}
<div class="post">
<h2>{{ post.title }}</h2>
<p>Posted on {{ post.timestamp }} by {{ post.author }}</p>
<p>{{ post.bodytext }}</p>
</div>
{% endfor %}
models.py:
from django.db import models
from django.utils import timezone
from django.conf import settings
from tinymce.models import HTMLField
class posts(models.Model):
author = models.CharField(max_length = 30)
title = models.CharField(max_length = 100)
bodytext = HTMLField()
timestamp = models.DateTimeField(default = timezone.now) # sets a default date & time value when creating a new post
class Meta:
verbose_name_plural = "posts" # sets the plural name of posts (default = postss)
def __str__(self):
return self.title
我想我忘记了做的事情。那么这里有什么问题?
答案 0 :(得分:2)
这是因为html被转义了。例如,如果您让匿名用户在您的网站上发布文章(或评论),并让他们自己编写html(以及javascript),那么可能会发生不好的事情。
如果您只是撰写帖子,请随时使用:
{{ post.bodytext|safe }}
有关此内容的更多信息:
https://docs.djangoproject.com/en/1.8/ref/templates/language/#automatic-html-escaping