Refresh A Div To Shows New Rating In Django Using Jquery And Ajax
I’m new to django and can’t find the way to refresh only the div and that the div shows me current rating with stars. My idea is that user can see average rating and rate somet
Solution 1:
First, copy the code inside the <div id="rating"></div>
and save it to another file. Lets say,
rating.html
<divclass="movierating"id="o_{{ object.id }}"><spanstyle="display:none;">{{ object.rating_vote.get_rating }}</span>
{{ object.rating_vote.get_rating }}
</div>
Now in your page, it will be,
your.html
............
<div id="rating">
{% include 'rating.html' %}
</div>
............
Then, create new view
and new url
for rating.html
urls.py
url(r'^rating/$', 'rating', name='rating'),
views.py
def rating(request):
//rating object herereturn render(request, 'rating.html', {
//call rating object variable here
})
Finally, in your ajax
.........
$.ajax({
url: vote_url,
success: function(){
alert('Vote successful!);
$("#rating").load("/app_name/rating/");
},
});
...........
Post a Comment for "Refresh A Div To Shows New Rating In Django Using Jquery And Ajax"