Created
November 24, 2010 16:23
-
-
Save vkgtaro/713915 to your computer and use it in GitHub Desktop.
quickstart flask
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, 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) |
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> | |
<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