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

311
Views
Django - Javascript: ¿Cómo puedo mostrar dinámicamente esos archivos en este iframe?

Estoy empezando a aprender Django Framework para mi proyecto.

Actualmente estoy tratando de hacer que esta nueva funcionalidad funcione. Sé lo que tengo que hacer, pero no sé cómo hacerlo.

Mostrar imagen (el iframe src está vacío, por eso el mensaje de error de Firefox

Estoy creando, para cada elemento de una matriz, un botón. Cada uno de esos elementos tiene un archivo txt que quiero mostrar en este iframe (debajo de esos botones).

Esta imagen muestra, en este caso, tres botones (3 elementos en el arreglo). Lo que quiero hacer es, cuando hago clic en uno de esos botones, cambiará el src del iframe para que coincida con el índice actual de la matriz (apuntará al src de un elemento). Luego mostrará el contenido del archivo txt en el iframe.

JS:

 function createHeader() { let iframe = document.getElementById("iframe-overplot") let buttons = document.querySelectorAll("div > div > div > button"); console.log(buttons); for (let i = 0; i < spectra_list.length; i++) { // the array let button = document.createElement("button"); button.innerText = " "; button.style.backgroundColor = colors[i]; button.classList.add("h-10", "py-1", "text-xl", "text-gray-100", "font-medium", "transition-colors", "hover:text-gray-900", "focus:outline-none", "display:inline-block", "flex-row", "w-1/2"); div_header.appendChild(button); button.addEventListener("click", function (){ // change the iframe src to "i" index }) } }

HTML:

 <div class="relative w-1/2 flex flex-col mr-1 border border-gray-400" id="div_header_iframe"> <div class="w-full flex flex-row" id = "div_header_buttons"> </div> <iframe class ="h-full rounded-r bg-gray-50 flex-col" src = "..." id ="iframe_overplot"></iframe> </div>

Intenté hacer una nueva definición en views.py:

 def get_headers_spectrum(request): spectra_list = SyntheticSpectra.objects.values('spec_type', 'collection', 'short_name').filter( calc_key__in=request.POST.getlist('spectra')) return '/' + 'pollux' + '/' + spectra_list.spec_type + '/'+ get_spectra_list.collection + '/' + 'FlatTable' + '/' + spectra_list.shortname + '.txt'

Lo agregué a urls.py:

 path('my-spectra/overplot/get_headers_spectrum', views.get_headers_spectrum, name='get_headers_spectrum'),

En este momento, sé lo que quiero hacer, pero no sé cómo hacer que todo eso funcione en conjunto. Si no entiendes algo, ¡avísame!

about 4 years ago · Juan Pablo Isaza
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!