Skip to content

Instantly share code, notes, and snippets.

@vkgtaro
Created November 24, 2010 16:23
Show Gist options
  • Save vkgtaro/713915 to your computer and use it in GitHub Desktop.
Save vkgtaro/713915 to your computer and use it in GitHub Desktop.
quickstart flask
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def index():
return 'Index Page'
@app.route('/hello')
def hello():
return "Hello World!"
@app.route('/user/<username>')
def show_user_profile(username):
return "user: " + username
@app.route('/post/<int:post_id>')
def show_post(post_id):
return "post_id: " + str(post_id)
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
app.logger.info(request.form['name'] + ' is login')
return render_template('login.html', name=request.form['name'])
else:
return render_template('login.html')
if __name__ == '__main__':
app.run(debug = True)
<!doctype html>
<title>Hello from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<form action="/login" method="post"><input type="text" name="name" /><input type="submit" /></form>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment