0

How to pass data from html form to python?

My Html Code:

<form id="form" name="passlink" method="post">
      <input
        id="videolink"
        placeholder="Search or Paste Video Link here"
        type="url"
        name="videolink"
      />
      <input id="download_button" type="submit" value="Submit" />
    </form>

1 Answers1

0
from flask import *

app = Flask(__name__)    

@app.route("/", methods=['GET','POST'])
def form():
    if request.method == "GET":
        return "You html code"
    data = dict(request.form)

if __name__ == "__main__":
    app.run()

Here data will give dict with the formatting like,

{
    "name1":"value1",
    "name2":"value2"
}
  • 2
    while this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please [include an explanation for your code](https://meta.stackoverflow.com/questions/392712/explaining-entirely-code-based-answers), as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Shanteshwar Inde Feb 14 '22 at 12:00