Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Low Level Request Handling
#11
Thank you for your answers so far.

I'd like to focus my intention for clarification:
I have a HTML site with a form to pick a a number that the user has to type in.

Now, I'd like to know what the Python code (on the server) is to simply receive this
number and put it into a value called "number".

This intention is very simple, but I want to know how it works.
Thanks again!
Reply
#12
(Mar-15-2017, 01:21 PM)c0da Wrote: I have a HTML site with a form to pick a a number that the user has to type in.
I'd like to focus my intention for clarification:

Now, I'd like to know what the Python code (on the server) is to simply receive this
number and put it into a value called "number".
What language and server are you running?

When you have a html form and a number get submit,
it's send data to server and you process it there(if eg sever run PHP you get vaule with number = $_POST['data from form'])
If eg run Python(Flask) as server i get data with number = request.form['data from form']

When looking at this from outside(no server access) can use Requests to make post requests.
import requests

url = "http://127.0.0.1:5000/" # Eg my local Flask server
# Construct POST request
form_data = {
    'my-form' : "Send",
    'text' : 5
}

post = requests.post(url, data=form_data)
number = post.text
print(number) #--> 5
So i am doing a POST requests on this html code.
<!DOCTYPE html>
<html>
  <body>
    <form action="." method="POST">
      <input type="text" name="text">
      <input type="submit" name="my-form" value="Send">
    </form>
  </body>
</html>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python handling Apache Request harzsr 3 3,810 Nov-16-2018, 04:36 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020