開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 5.(Building a Webapp: Getting Real)の TEMPLATE MAGNETS(No. 4522) を取り組んでみる。
TEMPLATE MAGNETS(No. 4522)
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request
from vsearch import search4letters
app = Flask(__name__)
@app.route('/')
def hello() -> str:
return 'Hello world from Flask!'
@app.route('/search4', methods=['POST'])
def do_search() -> 'html':
phrase = request.form['phrase']
letters = request.form['letters']
title = 'Here are your results:'
results = str(search4letters(phrase, letters))
return render_template('results.html',
the_title=title,
the_phrase=phrase,
the_results=results,
the_letters=letters)
@app.route('/entry')
def entry_page() -> 'html':
return render_template('entry.html',
the_title='Welcome to search4letters on the web!')
if __name__ == '__main__':
app.run(debug=True)
入出力結果(Terminal, IPython)
$ ./vsearch4web.py * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 873-014-066 127.0.0.1 - - [24/Jul/2017 14:28:43] "GET / HTTP/1.1" 200 - 127.0.0.1 - - [24/Jul/2017 14:28:43] "GET /entry HTTP/1.1" 200 - 127.0.0.1 - - [24/Jul/2017 14:28:43] "GET /static/hf.css HTTP/1.1" 404 - 127.0.0.1 - - [24/Jul/2017 14:28:43] "GET /entry HTTP/1.1" 200 - 127.0.0.1 - - [24/Jul/2017 14:28:43] "GET /static/hf.css HTTP/1.1" 404 - 127.0.0.1 - - [24/Jul/2017 14:28:48] "POST /search4 HTTP/1.1" 200 - 127.0.0.1 - - [24/Jul/2017 14:28:48] "GET /static/hf.css HTTP/1.1" 404 - 127.0.0.1 - - [24/Jul/2017 14:29:06] "POST /search4 HTTP/1.1" 200 - 127.0.0.1 - - [24/Jul/2017 14:29:06] "GET /static/hf.css HTTP/1.1" 404 - C-c C-c$
0 コメント:
コメントを投稿