# Using Django code inside javascript

**URL:** <https://forum.djangoproject.com/t/using-django-code-inside-javascript/7907>\
**Category:** Using Django\
**Created:** [May 13, 2021, 7:33pm UTC](https://forum.djangoproject.com/t/using-django-code-inside-javascript/7907 "2021-05-13T19:33:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahuldutta0292](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rahuldutta0292/32/4540_2.png) [@rahuldutta0292](https://forum.djangoproject.com/u/rahuldutta0292)\
**Post date:** [May 13, 2021, 7:33pm UTC](https://forum.djangoproject.com/t/using-django-code-inside-javascript/7907/1 "2021-05-13T19:33:20Z")

</div>

I have a dynamic table containing a select list of items. While i click the add riw button, I’m trying to append a django for loop in javascript:

var fieldHTML = ’ {% for item in item\_list %} {{item.item\_name}} {% endfor %} Select Item ';  
$(wrapper).append(fieldHTML);

But in the django template it is showing as  
{{item.item\_name}} in the dropdown select list.

Kindly help

---

<div class="post-metadata">

**Author:** ![nemecek\_f](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/nemecek_f/32/668_2.png) [@nemecek\_f](https://forum.djangoproject.com/u/nemecek_f)\
**Post date:** [May 13, 2021, 7:35pm UTC](https://forum.djangoproject.com/t/using-django-code-inside-javascript/7907/2 "2021-05-13T19:35:58Z")

</div>

Hi,

if I understand correctly that you want your JavaScript to trigger Django templating then that is not possible.

Django templates are rendered on the server and send to the browser. You cannot modify them once they are rendered.

---

<div class="post-metadata">

**Author:** ![rahuldutta0292](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rahuldutta0292/32/4540_2.png) [@rahuldutta0292](https://forum.djangoproject.com/u/rahuldutta0292)\
**Post date:** [May 13, 2021, 7:47pm UTC](https://forum.djangoproject.com/t/using-django-code-inside-javascript/7907/3 "2021-05-13T19:47:17Z")

</div>

![Screenshot_2021-05-14-01-14-33-892_com.miui.notes](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/c/c6bd0c50dafa036df95e51de1f8360e8bdd96300.jpeg)

Thank you for the quick response.

Is there any way to dynamically append this row everytime a button is clicked

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 13, 2021, 8:22pm UTC](https://forum.djangoproject.com/t/using-django-code-inside-javascript/7907/4 "2021-05-13T20:22:20Z")

</div>

If you’re looking to dynamically add data to your page, where that data is Django-template-rendered, your JavaScript would need to make an AJAX call to a view that generates the appropriate HTML and returns it. The JavaScript then appends that fragment to your page.

---

<div class="post-metadata">

**Author:** ![rahuldutta0292](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rahuldutta0292/32/4540_2.png) [@rahuldutta0292](https://forum.djangoproject.com/u/rahuldutta0292)\
**Post date:** [May 13, 2021, 8:24pm UTC](https://forum.djangoproject.com/t/using-django-code-inside-javascript/7907/5 "2021-05-13T20:24:52Z")

</div>

Thank you very much…
