0

I am beginner in web development. I have an button Using HTML and CSS. Like this,

.button_1 {
  position: relative;
  padding: 20 px;
  top: 95px;
  left: 45px;
}

.button_1 input {
  display: none;
}

.button_1_span {
  width: 100px;
  height: 40px;
  background: red;
  display: block;
  overflow: hidden;
  cursor: pointer;
  transition: 0.4s;
  border-radius: 15px;
}

.button_1_span:before {
  content: '';
  width: 32px;
  height: 32px;
  left: 4px;
  bottom: -36px;
  background: black;
  position: absolute;
  border-radius: 15px;
}

.button_1 input:checked+.button_1_span {
  background: green;
}

.button_1 input:checked+.button_1_span:before {
  left: 64px;
}
<label class="button_1">
        <input type="checkbox">
        <span class="button_1_span"></span>
</label>

In this button there is two position red and green. Now, I want to call two python function using flask depends on red and green position of my button. Sample flask code is given here,

app.py

from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
  return render_template('button.html')

@app.route('/at_red_position_button/')
def my_detection():
  print ('From  red_position_button')

  return 'Red.'
  

@app.route('/at_green_position_button/')
def my_reading():
  print ('From  Green_position_button')

  return 'Green.'
  

if __name__ == '__main__':
  app.run(debug=True)

As, I am beginner I will appreciate any kinds of help. Thanks in advance.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Please ***[Do some research](https://www.google.com/search?q=call+flask+on+click+site:stackoverflow.com)***, search for related topics on SO; – mplungjan Oct 07 '20 at 07:39
  • jQuery: `$(".button_1 input").on("click",function() { $.get(this.checked? "/at_green_position_button/" : "/at_red_position_button/", function(data) { console.log(data)})` – mplungjan Oct 07 '20 at 07:43
  • @mplungjan I am not familiar with jQuery. Could you please add an answer how to do that, it would be helpful for me ? Anyway, Thanks for you help. –  Oct 07 '20 at 07:57
  • 1. Add `` to the head of the html page – mplungjan Oct 07 '20 at 08:00
  • 2. Add `` after the first script tag – mplungjan Oct 07 '20 at 08:01
  • @mplungjan Thanks a lot for your help. But I can't do that. Can you share any [codepen](https://codepen.io/) link or in other online cite. My project was emergency, plzz help. –  Oct 07 '20 at 08:09
  • What does "I can't do that" mean? – mplungjan Oct 07 '20 at 08:10
  • Sorry for my language. I can't realize where should be placed. So that is my problem. –  Oct 07 '20 at 08:11
  • Between the `` tags in your HTML document – mplungjan Oct 07 '20 at 08:14
  • Like this: https://jsfiddle.net/mplungjan/j3ecnbur/ – mplungjan Oct 07 '20 at 08:17

0 Answers0