I have the following Django view method, being used to send information over to some Vue.js frontend code in details.html. I am basically wondering how do I send over the data to the vue template. How do I do JSON dumps? I think that is what I am messing up here.
def works(request):
heading_info = Heading.objects.order_by('-name')[:1]
welcome_info = Welcome.objects.order_by('-title')[:1]
skills_info = Skill.objects.order_by('position')[:5]
projects_info = Project.objects.order_by('name')[:10]
items = []
items.append({'heading_info':heading_info, 'welcome_info':welcome_info, 'path':path, 'path2':path2, 'skills_info':skills_info,'projects_info':projects_info})
# context = {}
# context["items_json"] = json.dumps(items)
context = {'heading_info':heading_info, 'welcome_info':welcome_info, 'path':path, 'path2':path2, 'skills_info':skills_info,'projects_info':projects_info}
return render(request, 'home/details.html', context)
And here is my html where I am trying to access this data.
<script type='text/javascript'>
var data = {{ projects_info|safe }};
</script>
<div id="app">
[[projects_info_vue]]
{% comment %} #Passing array as vue data. This gets rendered as QuerySet. How do I access these value in Vue. {% endcomment %}
<div class="row">
{% for project in projects_info %}
{% comment %} #Here is the array being rednered in Django. This array gets rendered as a QuerySet in Vue. {% endcomment %}
<div class="col">
{{project.name}}
</div>
{% endfor %}
</div>
</div>
<script>
var app = new Vue({
delimiters: ["[[", "]]"],
el: '#app',
data: {
projects_info_vue: '{{projects_info}}',
},
});
</script>