I have been trying to retrieve an Array to my HTML page from my python script(view.py) which looks like this-
def archive(request):
posts = BlogPost.objects.all()
myVal = ["Dog Toys", "Dog Bedding", "Dog Feeding", "Health & Hygiene"]
t = loader.get_template("archive.html")
c = Context({'myposts' : simplejson.dumps(myVal)})
return HttpResponse(c)
My JavaScript on test.html looks like this -
<script>
var results = '{{myposts}}';
console.log(results);
</script>
The problem I have here is that my array is printed directly on the HTML page meaning my page source has only this -
1 : {'myposts': '["Dog Toys", "Dog Bedding", "Dog Feeding", "Health & Hygiene"]'}
i ams ure there is a way to overcome this, just not sure how to do it, I am working with Python/Django & JavaScript for the first time.
Thanks in advance for the help