Created
April 11, 2016 20:03
-
-
Save waynew/ce1117d6ba2d787bc7d97dbc38fbc2ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, redirect, url_for, render_template | |
app = Flask(__name__) | |
def get_light_states(): | |
return 'blue', 'no yellowwwww!' | |
@app.route('/') | |
def main(): | |
return render_template('index.html', button_status=get_light_states()) | |
@app.route('/light_one', methods=['POST']) | |
def light_one(): | |
print('Turning light one on or off or something') | |
return redirect(url_for('main')) | |
@app.route('/light_two', methods=['POST']) | |
def light_two(): | |
print('Turning light two on or off or something') | |
return redirect(url_for('main')) | |
if __name__ == '__main__': | |
app.run('0.0.0.0', 8000, debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<form action="{{ url_for('light_one') }}" method="POST"><button type="submit">Light One</button></form> | |
<form action="{{ url_for('light_two') }}" method="POST"><button type="submit">Light Two</button></form> | |
<ul> | |
{% for status in button_status %} | |
<li>{{ status }}</li> | |
{% endfor %} | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
should be templates/index.html