I am a Django novice attempting to build an app that allows users to add tracks to a playlist. I use sessions to generate a list of track id strings in a view and return an http response with the serialized array. The problem is that trying to iterate through the array in the template to build an ordered list does not format properly. It displays as a python list instead of the expected bulleted html list.
Any help would be greatly appreciated!
the Div
<!DOCTYPE html>
<div id="playlist">
<ol>
{% for track in playlist %}
<li>{{track}}</li>
{% endfor %}
</ol>
</div>
</html>
the javascript
<script type="text/javascript">
$(document).on('submit', '.track_form', function() {
var $form = $(this);
$.ajax({
url: $form.attr('action'),
data: $form.serialize(),
type: $form.attr('method'),
success: function (data) {
$("#playlist").html(data);
},
error: function(data) {
console.log('There was a problem');
}
});
return false;
});
</script>
the view
def artistpage(request):
if request.method == 'POST':
session_playlist = request.session.get('session_playlist', [])
tname = str(request.POST.get('track_name'))
session_playlist.append(tname)
request.session['session_playlist'] = session_playlist
return HttpResponse(json.dumps(session_playlist))