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

199
Views
La plantilla JSONField Django no me muestra lo que fui

despues de mucho investigar aun no he encontrado como hacerlo: mi proposito es poder separar mi json en claves/valores para mostrar solo lo que me parece necesario (por ejemplo el titulo, los autores,.. .). Es una web de Django Site. Que he hecho:

En modelos.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'

En Vistas.py

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

*Y la plantilla: post_json.html*

Esto me muestra completamente mis datos json

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

Y esto es lo que estoy tratando de mostrar solo a los autores.

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

La pantalla en mi página web: ingrese la descripción de la imagen aquí

Gracias de antemano por su ayuda (perdón si hay errores de inglés, soy francés)

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para acceder a las claves de post.publis en la plantilla de Django, utiliza la búsqueda de puntos normal, por ejemplo, {{ post.publis.UT }} .

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

Poner aa = {{ post.publis }} en su plantilla no asigna post.publis a aa . Si desea evitar la duplicación de post.publis , puede usar la etiqueta with .

 {% 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!