I know similar questions have been asked before but I am very new to django and js. I have tried many solutions but I am not able to make sense of many and able to run them. So I am writing my code and the solution that I have tried. Can someone please tell me what mistake am I doing.
In my views.py I am handling a file which produces some results. These results are in the form of a Dataframe(used pandas). From this dataframe I am calculating few integer values which are stored in variables: tot,p,lp,us. I am also getting 3 sub-dataframes namely: dfp,dflp,dfus. I need to display all these on the webpage so I am sending them to an html: uploaded.html as shown below.
dict_1 = {'Path':p, 'LPath':lp, 'USig':us}
json1 = json.dumps(dict_1)
return render(request, 'uploaded.html', locals(), {'js_json1': json1, 'TotVar': tot})
The above code just sends the variables and not the dataframe as I don't know how to do it. I have handled it in my uploaded.html in the following way:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Upload File-Hereditary Cancers</title>
<link rel="stylesheet" href="/static/css/style.css" type="text/css">
<script type="text/javascript">
function results()
{
var totalvariants = {{TotVar}};
document.getElementById("totvar").innerHTML = "Total number of variants are: "+totalvariants;
}
</script>
</head>
<body>
<div id="header">
<div>
<div class="logo">
<a href="index.html">Hereditary Cancers</a>
</div>
<ul id="navigation">
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="about.html">About</a>
</li>
<li class="active">
<a href="uploadfile.html">Upload File</a>
</li>
<li>
<a href="team.html">Team</a>
</li>
<li>
<a href="contact.html">Contact Us</a>
</li>
</ul>
</div>
</div>
<div>
{% if saved %}
<strong>Your file was uploaded.</strong>
<button onclick = "results()">Results</button>
<p id = "totvar">This will change</p>
{% endif %}
{% if not saved %}
<strong>Your file was not uploaded.</strong>
{% endif %}
</div>
<div id="footer">
<div class="clearfix">
<div id="connect">
<a href="http://freewebsitetemplates.com/go/facebook/" target="_blank" class="facebook"></a><a href="http://freewebsitetemplates.com/go/googleplus/" target="_blank" class="googleplus"></a><a href="http://freewebsitetemplates.com/go/twitter/" target="_blank" class="twitter"></a><a href="http://www.freewebsitetemplates.com/misc/contact/" target="_blank" class="tumbler"></a>
</div>
<p>
© 2023 Zerotype. All Rights Reserved.
</p>
</div>
</div>
</body>
</html>
I am creating a button in my html which activates the script on click. I haven't done much in my script because I don't know how to. I have just tried to display the tot variable which is also not getting displayed.Can anyone tell me the complete script on how I can handle dataframes and variables in my js function and display their results.