Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

javascript function from python flask

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Upload new File</title>
</head>
<body onload="flashMessage()">
  <script>
    function flashMessage() {
      if ("{{ flash_message }}" == "True") {
        alert("[YOUR_MESSAGE_HERE]");
      }
    }
  </script>

  <h1>Upload new File</h1>
  <form method=post enctype=multipart/form-data>
    <input type=file name=file>
    <input type=submit value=Upload>
  </form>
</body>
</html>
Comment

call javascript function flask

from flask import Flask, render_template

app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        #verify if the file is valid
        #here invoke js to do something (for example flash("test"))
        return render_template('upload.html', flash_message="True")

    return render_template('upload.html', flash_message="False")
Comment

call javascript function from flask

from flask import Flask, render_template

app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        #verify if the file is valid
        #here invoke js to do something (for example flash("test"))
        return render_template('upload.html', flash_message="True")

    return render_template('upload.html', flash_message="False")
Comment

javascript call flask function

from flask import Flask, jsonify, render_template, request
app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')

@app.route('/SomeFunction')
def SomeFunction():
    print('In SomeFunction')
    return "Nothing"



if __name__ == '__main__':
   app.run()
Comment

PREVIOUS NEXT
Code Example
Python :: how to form .cleaned data in class based views in django 
Python :: multiple line string 
Python :: List Comprehension iteration 
Python :: using shebang python 
Python :: python typing 
Python :: check if variable is none 
Python :: python dynamic variable name 
Python :: python Using for loop and list comprehension 
Python :: extract directory python 
Python :: additionner liste python 
Python :: how to compare list and int in python 
Python :: doctest python 
Python :: sanke in python 
Python :: clear many to many django 
Python :: how add a favicon to django 
Python :: what is * in argument list in python 
Python :: django login required as admin 
Python :: tensorflow 
Python :: Join query flask-sqlalchemy 
Python :: operator overloading python 
Python :: pandas fillna multiple columns 
Python :: how to split a string by space in python 
Python :: how to create a new dataframe in python 
Python :: remove n characters from string python 
Python :: kaspersky 
Python :: python list operation 
Python :: how to import somthing from another directory in pyhon 
Python :: object python 
Python :: frequency 
Python :: read user input python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =