Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!