after reading bunch of blogs can not find answer, searched in well.
i have template use django template tags:
<div class="box" id="dates"> <h2 class="h2">dates</h2> <ul class="list-group"> {% days in dates %} <li class="list-group-item list-group-item-success">{{ days }}</li> {% endfor %} </ul> </div>
this div waits answer comes ajax response. here ajax code:
$("#formi").submit(function(event){ event.preventdefault(); var data = new formdata($('form').get(0)); $.ajax({ type:"post", url:"{% url 'dates' %}", data: data, processdata: false, contenttype: false, csrfmiddlewaretoken: '{{ csrf_token }}', success: function(data){ console.log("yeeeeeeeeeeeeeeeeaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhh") $("#dates").html({{ data.dates }}); }, }); });
pretty self explainatory. sends form view , view responds json data going used fill for loop
in template.
i can see data getting template in th console
but u can see not recognizing {{data.dates}}
tag after $("#dates").html
in ajax succes
so, how can still use django tags in template , data out of ajax response?
thanks in advance provided.
data
plain text, not python variable can't print out within {{ }}
. looks json object, can following:
assuming have jquery
installed:
$.each(data.dates, function(i, val) { $('ul.list-group').empty().append( $('<li>').addclass('list-group-item list-group-item-success').text(val) ) });
Comments
Post a Comment