I'm trying to parse a string variable, "articlename" to my main Flask Python script from HTML (with JS). However, all it returns is None. How can I fix this?
HTML/JS:
<p><button id="likebutton" onclick="likePost()"><img class="likebuttonimg" src="static/images/clearlike.png" id = image></button></p><p> {{likes}} likes {{views}} views</p><script> let data = new FormData() data.append("name", "sketchystrats") document.getElementById("likebutton").onclick = function () { fetch('/tracklikes', { method: 'POST', headers: {'name': 'sketchystrats'}, body: JSON.stringify(data), }) };</script>
Relevant section of Python:
@app.route("/tracklikes", methods=['POST'])def tracklikes(): print("TrackLikes activated") articlename = request.form.get('data') print(str(articlename))
Then it does some database stuff that isn't super relevant. For note, I don't know what I'm doing when it comes to Javascript.