博客文章仅显示原始代码,不显示图像,粗体文本或其他属性……Django / Ckeditor

问题描述 投票:0回答:1

我遵循了有关在我的博客中实现ckeditor RichTextUploadingField()的教程,因此我可以拥有更多的功能和更好的帖子/博客。

一切似乎都正常,但是当我在添加图片和一些文字之后去看实际的帖子时。我的所有文字都得到原始输出...

这是我在博客上的输出

<p><span style="color:#1a1a1a"><span style="background-color:#ffffff">First of all, I have assumed that you have seen countless rubbish articles, and still can&#39;t understand classes and objects, but at least know that there are two things like classes and objects.</span></span></p>

<p><span style="color:#1a1a1a"><span style="background-color:#ffffff">Since you don&#39;t have programming experience, you can&#39;t understand Python&#39;s &#39;classes and objects&#39; by analogy from the programming language you&#39;ve learned.&nbsp;Let&#39;s use the example of life to build a house.</span></span></p>

<p>&nbsp;</p>

<p><span style="color:#1a1a1a"><span style="background-color:#ffffff"><img alt="" src="/media/upload/2019/11/08/01.png" style="height:268px; width:400px" /></span></span></p>

不确定在编辑和创建文章之前,为什么它看起来不像我在获得文章之前得到的输出。


MODELS.PY

from ckeditor_uploader.fields import RichTextUploadingField
from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse
from django.utils import timezone


class Post(models.Model):
    title = models.CharField(max_length=100)
    # content = models.TextField()
    content = RichTextUploadingField()
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return f'{self.title} --> {self.author}'

    def get_absolute_url(self):
        return reverse('post-detail', kwargs={'pk': self.pk})

POST_DETAIL.HTML

{% extends "portfolio_app/base.html" %}
{% block content %}
    <div class="py-5 bg-light">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <article class="media content-section">
                        <img class="rounded-circle article-img" src="{{ object.author.profile.image.url }}">
                        <div class="media-body">
                            <div class="article-metadata">
                                <a class="mr-2" href="{% url 'user-posts' object.author.username %}">{{ object.author }}</a>
                                <small class="text-muted">{{ object.date_posted|date:'F d, Y' }}</small>
                                {% if object.author == user %}
                                    <div>
                                        <a class="btn btn-secondary btn-sm mt-1 mb-1" href="{% url 'post-update' object.id %}">Update Post</a>
                                        <a class="btn btn-danger btn-sm mt-1 mb-1" href="{% url 'post-delete' object.id %}">Delete Post</a>
                                    </div>
                                {% endif %}
                            </div>
                            <h2 class="article-title">{{ object.title }}</h2>
                            <p class="article-content">{{ object.content }}</p>
                        </div>
                    </article>
                </div>
            </div>
        </div>
    </div>
{% endblock content %}

POST_FORM.HTML

{% extends "portfolio_app/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
        <div class="container col-md-6">
            <div class="content-section">
                <div class="content-section">
                    <form method="POST">
                        {% csrf_token %}
                        <fieldset class="form-group">
                            <legend class="border-bottom md-4">Blog Post</legend>
                            {{ form.media }}
                            {{ form|crispy }}
                        </fieldset>
                        <div class="form-group">
                            <button class="btn btn-outline-info" type="submit">Post!</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
{% endblock content %}

我想念什么吗??再次感谢您的帮助。

django ckeditor blogs
1个回答
0
投票

使用安全过滤器。

<h2 class="article-title">{{ object.title|safe }}</h2>
<p class="article-content">{{ object.content|safe }}</p>
© www.soinside.com 2019 - 2024. All rights reserved.