Не удается получить доступ к тексту, сохраненному в поле формы Quill в шаблоне Django

В моем шаблоне django я хочу получить доступ к биорекламе экземпляра моего класса Creator. Эта биография настроена как QuillField в классе моделей Creator. Когда я пытаюсь получить доступ к Creator.bio, все, что отображается на странице, это следующее:

‹django_quill.fields.FieldQuill объект по адресу 0x1084ce518›

Что мне нужно, так это фактический абзац форматированного текста (т.е. биография), который я ввел в форму и сохранил. На данный момент QuillField доступен только через форму на странице администрирования Django. Проблема не имеет ничего общего с пользовательским интерфейсом Quill, а скорее с возможностью доступа к тексту, который я написал в этом поле формы, и отобразить его на странице в удобочитаемом формате.

Из моделей.py:

from django.db import models
from django_quill.fields import QuillField

class Creator(models.Model):
    name = models.CharField(max_length=100)
    title = models.CharField(max_length=100, default='Creator')
    bio = QuillField()
    photo = models.ImageField(upload_to='images/', default='static/assets/icons/user-solid.svg')
    email = models.EmailField(max_length=100)
    website = models.URLField(max_length=1000, blank=True)
    facebook = models.URLField(max_length=1000, blank=True)
    twitter = models.URLField(max_length=1000, blank=True)
    instagram = models.URLField(max_length=1000, blank=True)

    def __str__(self):
        return self.name

В представлениях.py:

def about(request):
    context = {"creators" : Creator.objects.all()}
    return render(request, 'about.html', context)

И в шаблоне:

        <section id="creator-container">
            {% for creator in creators %}
                <div class="creator-square">
                    <h4>{{ creator.name }}</h4>
                    <h5>{{ creator.title }}</h5>
                    <img src="../../media/{{ creator.photo }}" alt="{{actor.name}} headshot" id="creator-photo">
                    <p class="creator-bio">{{ creator.bio }}</p>
                </div>
            {% endfor %}
        </section>

Если я выведу объект Creator.bio на консоль, то получу следующее:

{"delta":"{\"ops\":[{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"bold\":true},\"insert\":\"Sharon Yablon\"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\" is an award-winning playwright who has been writing and directing her plays in Los Angeles for many years. Her work has appeared in a variety of sites, and on stage with The Echo Theater Company, Padua Playwrights, Zombie Joe's Underground Theater, The Lost Studio, Theater Unleashed, Bootleg, Theater of N.O.T.E., and others. Her short stories, \\\"Perfidia\\\" and \\\"The Caller,\\\" can be found in journals, and her published plays are in \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"italic\":true},\"insert\":\"Desert Road's One Acts of Note\"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\", \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"italic\":true},\"insert\":\"Fever Dreams\"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\", \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"italic\":true},\"insert\":\"Los Angeles Under the Influence\"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\", \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"italic\":true},\"insert\":\"LA Writers and Their Works\"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\", and others. She was co-editor of an anthology of plays from the LA underground scene titled \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"italic\":true},\"insert\":\"I Might Be The Person You Are Talking To, \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\"and most recently, her play \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"italic\":true},\"insert\":\"Hello Stranger\"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\" (Theater of N.O.T.E., 2017) was published by Original Works. She is a frequent writer and sometime co-curator with Susan Hayden's \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"italic\":true},\"insert\":\"Library Girl\"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\", a \\\"Best of the Westside\\\" monthly literary series centered around a music theme. Her one-acts inspired by crimes in LA history have appeared in \"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\",\"italic\":true},\"insert\":\"LA True Crime’s\"},{\"attributes\":{\"background\":\"transparent\",\"color\":\"#000000\"},\"insert\":\" quarterly evenings since its inception in 2015. \"},{\"insert\":\"\\n\"}]}","html":"<p><strong style=\"background-color: transparent; color: rgb(0, 0, 0);\">Sharon Yablon</strong><span style=\"background-color: transparent; color: rgb(0, 0, 0);\"> is an award-winning playwright who has been writing and directing her plays in Los Angeles for many years. Her work has appeared in a variety of sites, and on stage with The Echo Theater Company, Padua Playwrights, Zombie Joe's Underground Theater, The Lost Studio, Theater Unleashed, Bootleg, Theater of N.O.T.E., and others. Her short stories, \"Perfidia\" and \"The Caller,\" can be found in journals, and her published plays are in </span><em style=\"background-color: transparent; color: rgb(0, 0, 0);\">Desert Road's One Acts of Note</em><span style=\"background-color: transparent; color: rgb(0, 0, 0);\">, </span><em style=\"background-color: transparent; color: rgb(0, 0, 0);\">Fever Dreams</em><span style=\"background-color: transparent; color: rgb(0, 0, 0);\">, </span><em style=\"background-color: transparent; color: rgb(0, 0, 0);\">Los Angeles Under the Influence</em><span style=\"background-color: transparent; color: rgb(0, 0, 0);\">, </span><em style=\"background-color: transparent; color: rgb(0, 0, 0);\">LA Writers and Their Works</em><span style=\"background-color: transparent; color: rgb(0, 0, 0);\">, and others. She was co-editor of an anthology of plays from the LA underground scene titled </span><em style=\"background-color: transparent; color: rgb(0, 0, 0);\">I Might Be The Person You Are Talking To, </em><span style=\"background-color: transparent; color: rgb(0, 0, 0);\">and most recently, her play </span><em style=\"background-color: transparent; color: rgb(0, 0, 0);\">Hello Stranger</em><span style=\"background-color: transparent; color: rgb(0, 0, 0);\"> (Theater of N.O.T.E., 2017) was published by Original Works. She is a frequent writer and sometime co-curator with Susan Hayden's </span><em style=\"background-color: transparent; color: rgb(0, 0, 0);\">Library Girl</em><span style=\"background-color: transparent; color: rgb(0, 0, 0);\">, a \"Best of the Westside\" monthly literary series centered around a music theme. Her one-acts inspired by crimes in LA history have appeared in </span><em style=\"background-color: transparent; color: rgb(0, 0, 0);\">LA True Crime’s</em><span style=\"background-color: transparent; color: rgb(0, 0, 0);\"> quarterly evenings since its inception in 2015. </span></p>"}

Кто-нибудь знает, как получить к нему доступ, чтобы он правильно отображался как текст HTML?


person dylan_jamesss    schedule 01.02.2021    source источник
comment
Какую версию джанго вы используете? Этот пакет выглядит действительно устаревшим, поэтому его не следует использовать. Что касается данных, которые он сохраняет, похоже, что они сбежали из JSON.   -  person markwalker_    schedule 02.02.2021
comment
@markwalker_ Я использую Django 3.1.5. Это пакет Quill: pypi.org/project/django-quill-editor   -  person dylan_jamesss    schedule 02.02.2021


Ответы (1)


На основе https://github.com/LeeHanYeong/django-quill-editor/issues/12 похоже, вам нужно использовать:

{{ creator.bio.html|safe }}

(хотя будьте осторожны, используя safe, если вы не уверен, что HTML не является вредоносным!)

person DrMeers    schedule 02.02.2021
comment
ты настоящий MVP!! Бесконечно благодарен! - person dylan_jamesss; 03.02.2021