0

can i add a {% for in %} loop and {{ variables }} in django template using javascript dom (insertAdjacentText, or textContent) and charge data from the views something like refresh only the part of html that containt the added for loop or refresh the page without loosing the javascript execution ? if yes guide me i searched and i did not

function displayMaquette(){
let label = document.getElementById('label');
    let rem = document.getElementById('remove')
    let amg = document.getElementsByClassName('amg')
    let namep =document.getElementsByClassName('namep')
    let add =document.getElementById('add')
    add.insertAdjacentText('afterbegin','{% for plan in plan3 %}')
    add.insertAdjacentText('beforeend','{% endfor %}')*/
    for(let i =0;i<x.length;i++){
      x[i].textContent='{{ plan.IdPlans }}'
      amg[i].setAttribute('src','{{plan.Image.url}}')
      namep[i].textContent='{{ plan.NamePlan }} :'

    }
}
<figure id="label3" class="fig" onclick="displayMaquette()">
        <figcaption class="caption" onmouseover="figCaptionHover(this)" onmouseout="figCaptionOut(this)">Cliquez pour afficher les maquettes</figcaption>
        <img class="figimg" src="" alt="Elephant at sunset" >
        </figure>
</div>


<article class="works none">
    <p class="pNone" style="display: none;"></p>
    <div class="worksimg">
          <img class="Img amg" Img src="">
          </div>
        <div class="Description">
        <h2 class="namep"></h2>
        <p></p>
    </div>  
</article>

<div id="remove"></div>

find? By onclick event i add the for loop and {{ variables }} but it display as text in the browser it doesn't charge datas from views what i wan't is charge data from database

1 Answer 1

1

It sounds like the javascript you're referring too is running on the client's computer. If that is the case then no this is not possible. Django templates are evaluated by the server before it sends a response to the client. The client has no way of knowing what django tags are and how to use them since that is a feature built into django itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.