0

I am new to flask and web development and having hard time figuring out calling a function inside my flask python app from html side.

I am trying to create a button to invoke a function in my python (2.7) side.

I tried below html button and python code, but realized it cause submission and web page refreshing.

html side:

<form method="POST" action="/">    
   <input type="submit" name="Click">

python side:

@app.route('/', methods=['post'])
def foo():
   # some operations here

So, I was thinking that I can do something similar to below but, I am having hard time finding out what to do once javascript catches the event.

html side:

<button onclick="my_foo()">Click</button> 

<script>
function myFunction() {
    // let's call a function inside flask/python app
    // but how?
}
</script>

python side:

# how should this function be exposed?
def call_me():
   # trying to do something here

Could you please explain how to expose a function from flask app to html side without causing webpage refresh or creating form submission or post?

Thanks

Kay
  • 1,235
  • 2
  • 13
  • 27

0 Answers0