Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
from API to ip
#13
(Dec-05-2018, 10:19 PM)whatl0ol Wrote: what does it mean?
def my_form():
    return render_template('my-form.html')

@app.route('/', methods=['POST'])
def my_form_post():
    text = request.form['text']
    processed_text = text.upper()
    return processed_text 
It's a demo getting value from my-form.html to server.
So if i fix your first code(messy) it look like this.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>whatl0ol</title>
  <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>

<body>
  <div class="login">
    <div class="heading">
      <h2></h2>
      <form action="{{ url_for('main') }}" method='POST'>
        <div class="input-group input-group-lg">
          <span class="input-group-addon"><i class="fa fa-user"></i></span>
          <input type="text" name="input_field" class="form-control" placeholder="">
        </div>
        <button type="submit" id="send" name="send" class="float">check</button>
      </form>
    </div>
  </div>
</body>
</html>
app.py
import requests
from flask import Flask, jsonify, render_template, request

app = Flask(__name__)
@app.route('/')
def template():
   return render_template('index.html')
 
@app.route('/main', methods=['POST'])
def main():
    form_input = request.form['input_field']
    return(form_input)

if __name__  == ("__main__"):
    app.run(debug=True)
Run python app.py in browser paste http://127.0.0.1:5000/
So now get index.html rendered in browser.
When send value will get catch it in server with request.form['input_field']
and send it back to browser return(form_input)

Look at @nilamo links,
and HTML Forms is a standard way to send stuff from client side(Browser) to server(Flask in this case) in web-development.
Reply


Messages In This Thread
from API to ip - by whatl0ol - Dec-05-2018, 09:11 PM
RE: from API to ip - by nilamo - Dec-05-2018, 10:09 PM
RE: from API to ip - by whatl0ol - Dec-05-2018, 10:11 PM
RE: from API to ip - by nilamo - Dec-05-2018, 10:13 PM
RE: from API to ip - by whatl0ol - Dec-05-2018, 10:19 PM
RE: from API to ip - by nilamo - Dec-06-2018, 04:45 AM
RE: from API to ip - by whatl0ol - Dec-06-2018, 04:11 PM
RE: from API to ip - by nilamo - Dec-06-2018, 04:49 PM
RE: from API to ip - by whatl0ol - Dec-06-2018, 04:49 PM
RE: from API to ip - by nilamo - Dec-06-2018, 05:10 PM
RE: from API to ip - by snippsat - Dec-06-2018, 11:00 PM
html to python - by whatl0ol - Dec-06-2018, 12:36 AM

Forum Jump:

User Panel Messages

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