Thursday, March 1, 2012

How do i view json data returned from django

Hello,

I want to view the actual json data from django view, is there anyway i can do that before i parse it into jQuery?

Below are my two methods

def refresh_list(request):
if request.method == 'POST':
if 'name_input2' in request.POST:
username = request.POST['name_input2']
print username
refresh_keyword = get_keyword_subscription_dict(username)
#message = refresh_keyword
response = simplejson.dumps({'new_list': refresh_keyword})
return HttpResponse(response, mimetype='application/json')
print 'Success'
else:
response = simplejson.dumps({'success':'False'})
if request.is_ajax():
return HttpResponse(response, mimetype='application/json')
else:
return HttpResponseRedirect("/")

def get_keyword_subscription_dict(userid = None, keyword = None):
try:
keyword_subscription_dict = {}
if(userid):
cf = settings.cf_users_kw
list_of_keywords_for_user_cf = cf.get(userid, columns=['keyword'])
keyword_subscription_dict = ujson.decode(list_of_keywords_for_user_cf['keyword'])
if(keyword):
return simplejson.dumps(keyword_subscription_dict[keyword])
return simplejson.dumps(keyword_subscription_dict)
except:
return simplejson.dumps('\\')

Do appreciate any help i can get

Thanks!

Best Regards,

Stanwin Siow

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment