Skip to content

Commit

Permalink
Add hello application for chapter 1
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli committed Jun 12, 2018
1 parent d445789 commit 9fad70d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions demos/hello/.flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLASK_ENV=development
32 changes: 32 additions & 0 deletions demos/hello/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
import click
from flask import Flask

app = Flask(__name__)


# the minimal Flask application
@app.route('/')
def index():
return '<h1>Hello, World!</h1>'


# bind multiple URL for one view function
@app.route('/hi')
@app.route('/hello')
def say_hello():
return '<h1>Hello, Flask!</h1>'


# dynamic route, URL variable default
@app.route('/greet', defaults={'name': 'Programmer'})
@app.route('/greet/<name>')
def greet(name):
return '<h1>Hello, %s!</h1>' % name


# custom flask cli command
@app.cli.command()
def hello():
"""Just say hello."""
click.echo('Hello, Human!')

0 comments on commit 9fad70d

Please sign in to comment.