If I startup the dev server and goto a certain view. I get no response.
my view is like the following
from django.http import HttpResponse, Http404
from goals.models import Child
import json
def viewChildren(request):
jsonData= []
allChildren = Child.objects.all()
for child in allChildren:
jsonData.append({'id': child.id, 'name': child.name})
return HttpResponse(json.dumps(jsonData),mimetype="application/json")
To test out what was going on, i did a the following
python manage.py shell
>>> import goals.views as v
>>> r = v.viewChildren('')
>>> print r
Content-Type: application/json
[{"id": 1, "name": "Test Child"}, {"id": 2, "name": "Second child"}]
So I know that the view is correct and the right data is being passed on after the view is called… But this isn’t being passed on when I view this from a browser.
Any suggestions?
(this is similar to a lot of questions but none that I have found have shown the above situation where the view IS providing the correct response but from a browser it is not)
Just solved the problem. I took out all of the rest of the urls as I thought maybe they weren’t correct. Turns out that a previous edit had made all urls goto a blank index one which returned no response. After fixing that, the above worked just fine.
Thanks for looking anyways…