So as mention in title, I'm trying to send my Django object to JavaScript so I can massage it in the front end. Let me show you the code (simplified). views.py
def main_page(request):
contents = Contents.objects.all()
context = {
'contents' : contents
}
return render(request, 'main/home.html', context)
template
{% for u in all_ans_us_paginated %}
<div class="row">
<div class="col">
<div class="" id="{{u.id}}" onclick="DetailModal('{{u}}')">
</div>
</div>
</div>
{% endfor %}
...
<script>
function DetailModal(u) {
console.log('{{u.author}}');
console.log('{{u.body}}');
}
</script>
My intention is to show a modal when the click event is triggered. But putting the modal part aside, I can't pass data as parameter to JavaScript.
*I don't want to make any changes in the python code. Is it possible to do it only with HTML and JavaScript?
**JSON.parse(u)
won't work, because u
is string.