Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16684

Parsing variable from HTML/JS to Python with Flask always returns None

$
0
0

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.


Viewing all articles
Browse latest Browse all 16684

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>