I'm on little task of django and I put some JavaScript section for endless scroll,
here is part of my html file.
{% for d in data reversed %}
<form method="POST" action="/SNS/{{d.id}}/">
{% csrf_token %}
<li>
<h5>{{d.content}}</h5>
<p>
{{d.date}}
<button type="submit" name="delete" value="delete">X</button>
</P>
</li>
</form>
{% endfor %}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="script.js"></script>
<script type="text/javascript">
var d = "{{data}}";
$(window).scroll(function() {
if($(window).scrollTop() == $(document).height() - $(window).height()) {
alert('End of Window');
}
});
</script>
data comes from views and it works well in html part.
but problem is this :
I want to use data variable in my script section.
so I declare var d like that, but it didn't work.
how can I use var from django in JavaScript?
edited : what I want to do ultimately is twitter-like endless scroll.
datas are in db, and page load some of them at first.
when user scroll down the page, page load some of the remain data.. ans so on.
I wrote code for scrolling down event, and I need to show the remaining data

data? Can you inspect the HTML in browser and let us know what value do you have for variabled?views.py,data = models.modelSNS.objects.all()datais a QuerySet, you'll need to serialize that data in order to pass it to a JS variable.datain the javascript and may be we can find an alternative.