Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
JSONField Django template doesn't show me what I went

after a lot of research, I still have not found how to do it: my purpose is to be able to separate my json in keys/values to only display what it seems to me necessary (for example the title, the authors, ...). It's a Django Site web. That I have done :

In models.py

class Production(models.Model):
    titre = models.CharField(max_length=255, blank=True)
    publis = JSONField()
    def __str__(self):
        return '%s' % (self.titre)
    class Meta:
        db_table = 'Production'

In Views.py

def post_json(request):
    posts = Production.objects.all()
    return render(request, 'appli/post_json.html', {'posts': posts})

*And the template : post_json.html *

This show me fully my json data

    {% for post in posts %}
    <div>
        <p>aa = {{ post.publis }}</p>
    </div>
    {% endfor %}

And this it's what I'm trying to show only the authors

 <h1>Publications lalala</h1>
         {% for post in posts %}
                aa = {{ post.publis }}
            <p> Num : {{ aa.UT }}</p>
            <p>Auteur : {{ aa.AU }} </p>
         {% endfor %}

The display on my web page : enter image description here

Thank you in advance for your help (sorry if there are mistakes of english I am french)

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

To access the keys from post.publis in the Django template you use the regular dot lookup, e.g. {{ post.publis.UT }}.

{% for post in posts %}
    <p>Num : {{ post.publis.UT }}</p>
    <p>Auteur : {{ post.publis.AU }} </p>
{% endfor %}

Putting aa = {{ post.publis }} in your template does not assign post.publis to aa. If you want to prevent the duplication of post.publis, you can use the with tag.

{% for post in posts %}
  {% with aa=post.publis %}
    <p>Num : {{ aa.UT }}</p>
    <p>Auteur : {{ aa.AU }} </p>
  {% endwith %}
{% endfor %}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda