Created
August 7, 2013 07:11
-
-
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
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
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