How to connect HTML form to Python backend

Viewed 450

I've got an HTML email form, and I want to be able to send myself an email with the form data. Here are my current problems:

How do I extract the data from the form once it's submitted and get it into Python? How do I link my Python script to my HTML page?

If those aren't possible, how would I extract the data from the form into some kind of file? If this is done in some other language like Javascript, that's fine, just please show how in your answer.

1 Answers

are you using Flask? It is hard to tell if you do not mention the web framework you are using.

I will assume that you are using Flask, here is how you can get the posted form input

subject = request.form.get('subject')
text = request.form.get('email')

Assuming you posted JSON instead, then you can get the data like this

data = request.get_json()

PS: Remember to set the content type to application/json when submitting the request.

Related