Chartjs-Can I interpret Django object values as JSON data within the JS script in my HTML?

0👍

Sorry I can’t give this in a comment yet, have you looked into this yet? Django Generic JSON views. Seems to me like it would fit nicely into your project and help with the output you need.

0👍

Your data is already output by the view. You can just convert to JSON as you serve it from within the view.

Great example provided by SimpleIsBetterThenComplex:

from django.http import JsonResponse

def profile(request):
    data = {
        'name': 'Vitor',
        'location': 'Finland',
        'is_active': True,
        'count': 28
    }
    return JsonResponse(data)

Leave a comment