how to use django template language inside script html tag using django-jsRender

59 views
Skip to first unread message

Yacin Omar

unread,
Apr 3, 2020, 10:00:40 AM4/3/20
to Django users
As I know, there is no way to use Django template language inside Javascript block so I searched for a way how to do it, I found a Django app on github  called django-jsrender but unfortunately, there isn't enough documentation for this app and when I tried to use it I couldn't and this is my code:

Capture.PNG

Antje Kazimiers

unread,
Apr 3, 2020, 11:41:54 AM4/3/20
to django...@googlegroups.com
I think you can use some basic template language within a script block like below. myData is a stringified json object, that worked for me.
antje
<script>
  {% if myData %}
    var table_data = {{ myData|safe }};
  {% else %}
    var table_data = null;
  {% endif %}
</script>

On Fri, Apr 3, 2020 at 4:00 PM Yacin Omar <yacino...@gmail.com> wrote:
As I know, there is no way to use Django template language inside Javascript block so I searched for a way how to do it, I found a Django app on github  called django-jsrender but unfortunately, there isn't enough documentation for this app and when I tried to use it I couldn't and this is my code:

Capture.PNG

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a1c20606-bf66-4638-a006-be592a938c66%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages