[Django] How to Use django + post + ajax + highcharts, djangohighcharts
Direct code display:
View. py file code
From django. http import JsonResponse # def ajax_kchart (request): times = request. POST ['shijian '] chnl = request. POST ['chnl '] chnl_data = keywork_chart (chnl, times) data_list = [] for j in chnl_data: data_list.append (j) return JsonResponse (data_list, safe = False)
Here we will focus on two points: the ajax_kchart function name and the json function returned by JsonResponse (data_list, safe = False ).
The ajax_kchart function name must appear in url configuration. It can be used only in Django 1.7 and later versions.JsonResponse. If the returned parameter is a list, set safe to False.
Url. py code:
url(r'^workchart/$', 'keywork.views.ajax_kchart', name='ajax_kchart'),
Template code:
{% Load staticfiles %} <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Finished!