Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
from API to ip
#11
(Dec-06-2018, 04:49 PM)nilamo Wrote: By submitting it in a post request.

how ?
Quote
#12
In html, you could use a form: https://www.w3schools.com/tags/tag_form.asp
Or, if you want to do it programmatically, you could use javascript: https://www.w3schools.com/xml/ajax_intro.asp
Or, if you're fine with adding jquery, https://api.jquery.com/jquery.post/

Without seeing some code, there isn't much help someone can give.
Quote
#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.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)