Skip to content

Instantly share code, notes, and snippets.

@waynew
Created April 11, 2016 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waynew/ce1117d6ba2d787bc7d97dbc38fbc2ea to your computer and use it in GitHub Desktop.
Save waynew/ce1117d6ba2d787bc7d97dbc38fbc2ea to your computer and use it in GitHub Desktop.
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)
<!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>
@waynew
Copy link
Author

waynew commented Apr 11, 2016

should be templates/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment