I have a question about update HTML when I use view.py. This is my part of HTML, I have many buttons, and when I click one of the buttons, it will pass just the corresponds data to view.
$.ajax({
url:"/file_parse/",
type:"POST",
contentType: "application/json",
data:JSON.stringify({
'data':dataname
})
You can see I post some data ,and get the Post data in my view's function, finally I save the result to my model(database). When I click one button, and my view's function will do something,so I get a different result every time when I click a different button.This is the first view, dopase is a function to save data and it is doing right:
@login_required(login_url='/login')
@api_view(['GET', 'POST'])
def file_parse(request):
uploadfile_info = upload_document.objects.all()
if request.method == 'POST':
info_name = request.data.get('data')
doparse(info_name)
file_name = re.findall(r'[^/]+(?!.*\/)', str(info_name))
data_list = ES_device.objects.filter(device_name = file_name)
# data_list = ES_device.objects.values('device_name', 'device_type').distinct()
context = {'data_list': data_list}
# return Response(context, None, 'logfile/data_bi.html')
return render(request, 'logfile/data_bi.html', context)
# return render_to_response('logfile/data_bi.html', locals())
else:
context = {'uploadfile_info': uploadfile_info}
return render(request, 'logfile/file_parse.html', context)`
This is url
url(r'^file_parse/$', file_parse),
url(r'^data_bi/$', data_to_list),
This is the view I want to show the result:
def data_to_list(request):
data_list = ES_device.objects.all()
context = {'data_list': data_list}
#return render(request, 'logfile/data_bi.html', context)
return render_to_response('logfile/data_bi.html', locals())
But when I click one button, the first view successfully execute,and the data is saved to model, but it can not open another html(data_bi.html),I know something is wrong,but couldn't find it. Please give me some advice and show me how to achieve this.THANKS a lot.