Calling a Python function from HTML is not working

codeDojo

In my HTML page, I have a button. When I click on the button it should call a Python function that takes a screenshot and save it in the same directory. I tried my Python method and it is working correctly on local. But when I used Flask to call the function from a HTML button, it does nothing and there are no errors. How to get the screenshot image ?

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

# Function to take the screenshot and save it
def takesc():
    with mss() as sct:
        sct.shot()

@app.route('/takeScreenshot')
def takeScreenshot():
    return takesc()

My HTML

<button onclick="{{ takeScreenshot }}">ScreenShoot</button>

I also tried to use 'url_for' as following, but still nothing happened:

<button onclick="{{ url_for('takeScreenshot') }}">ScreenShoot</button>
Ajax1234

Instead of a button, it is shorter use an href:

<a href='/takeScreenshot' class='my_button_class'>ScreenShoot</a>

You can then use css to add style under the .my_button_class class.

However, to use a button, you need to specify the redirect:

<button type="button" onclick="window.location.href='{{url_for( 'takeScreenshot') }}';">Display Table Y</button>

Also, takeScreenshot is not returning text to be rendered on the screen. takesc does not return anything, thus, it should be called before the route returns a response:

@app.route('/takeScreenshot')
def takeScreenshot():
   takesc()
   return "screen shot saved"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MVC Calling a function from a partial view is not working

From Dev

Calling a function from a HTML button

From Dev

Calling CPP function from python ctypes

From Dev

Calling function in render not working

From Dev

RobotFramework - Calling a function from python library

From Dev

Calling a Python Function from local working directory

From Dev

Calling a function from HTML to Python file

From Dev

Python calling a function from another function in a class

From Dev

Calling function from dll with pointer not working

From Dev

JavaScript calling function is not working

From Dev

Python: Map calling a function not working

From Dev

calling javascript function with an argument from html

From Dev

PHP calling function from another file not working

From Dev

Calling a function from within a function in Python

From Dev

Calling directive function from child directive not working

From Dev

calling php function from html page

From Dev

calling mvc function from razor html

From Dev

Node.js calling function from other function not working

From Dev

Python calling function in an function from another function

From Dev

JS - Calling function from function not working

From Dev

Calling a function contained in a phar from an html page

From Dev

Calling a switch case function from inside HTML

From Dev

Calling a Python function from HTML

From Dev

Calling a PHP Function from a HTML <Select> option

From Dev

Calling/Invoking a Javascript function from python a flask function within html

From Dev

Calling function from HTML to typescript not waited to finish

From Dev

Self not Working while calling from function

From Dev

Function calling is not working in optionmenu widget in python

From Dev

Calling a function from a JS file not working

Related Related

  1. 1

    MVC Calling a function from a partial view is not working

  2. 2

    Calling a function from a HTML button

  3. 3

    Calling CPP function from python ctypes

  4. 4

    Calling function in render not working

  5. 5

    RobotFramework - Calling a function from python library

  6. 6

    Calling a Python Function from local working directory

  7. 7

    Calling a function from HTML to Python file

  8. 8

    Python calling a function from another function in a class

  9. 9

    Calling function from dll with pointer not working

  10. 10

    JavaScript calling function is not working

  11. 11

    Python: Map calling a function not working

  12. 12

    calling javascript function with an argument from html

  13. 13

    PHP calling function from another file not working

  14. 14

    Calling a function from within a function in Python

  15. 15

    Calling directive function from child directive not working

  16. 16

    calling php function from html page

  17. 17

    calling mvc function from razor html

  18. 18

    Node.js calling function from other function not working

  19. 19

    Python calling function in an function from another function

  20. 20

    JS - Calling function from function not working

  21. 21

    Calling a function contained in a phar from an html page

  22. 22

    Calling a switch case function from inside HTML

  23. 23

    Calling a Python function from HTML

  24. 24

    Calling a PHP Function from a HTML <Select> option

  25. 25

    Calling/Invoking a Javascript function from python a flask function within html

  26. 26

    Calling function from HTML to typescript not waited to finish

  27. 27

    Self not Working while calling from function

  28. 28

    Function calling is not working in optionmenu widget in python

  29. 29

    Calling a function from a JS file not working

HotTag

Archive