(Dec-05-2018, 10:19 PM)whatl0ol Wrote: what does it mean?It's a demo getting value from
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
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.