Skip to content

Instantly share code, notes, and snippets.

@Smerity
Created August 7, 2013 07:11
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 Smerity/6171867 to your computer and use it in GitHub Desktop.
Save Smerity/6171867 to your computer and use it in GitHub Desktop.
Code example for http://www.reddit.com/r/learnprogramming/comments/1jv9ev/websites_and_coding/ Super short and sweet web app that takes a user's text and converts it to upper case
import flask
app = flask.Flask(__name__)
template = """
<form method="POST">
<textarea name="text"></textarea>
<input type="submit" value="Submit">
</form>
"""
@app.route('/', methods=['GET', 'POST'])
def make_upper():
# A POST means the user is sending us information
if flask.request.method == 'POST':
# Try to grab 'text' from what the user is sending
# If they didn't send anything, this defaults to None
text = flask.request.form.get('text')
if text:
# Let's transform the text before returning it
return text.upper()
else:
return "You didn't write any text..."
# If the user isn't sending us information, let's give them the 'main page'
# In general you'd use a template, but this is a simple example
return template
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment