Bottle
■テンプレートシンタックスBottleのテンプレートは、HTMLのほかに% if ~:や<%for i in range(9): array[i] = 0%>など、%の間はPythonのコードを記載する事ができる。
■Templatesテンプレートを使用するには「template」関数を使用する。テンプレートの配置は「./views/」フォルダ、もしくは「bottle.TEMPLATE_PATH」に登録されているパスを読み込んでくれる。なので読み込んでほしいフォルダを指定する場合は「bottle.TEMPLA…
■Query Variablesクエリパラメータの指定はrequest.query.文字列で指定可能。# coding:utf-8from bottle import route, request, response, template@route('/test')def test(): no = request.query.luckyno or 0 return template('Lucky No.{{no}}', no=no)…
■CookiesCookieの発行はresponse.set_cookie()を使用。Cookieの取得はrequest.get_cookie()を使用する。# coding:utf-8from bottle import route, run, request, response@route('/hello')def cookie_test(): if request.get_cookie("cookie_test"): return …
■HTTP Errors and Redirectsということで、特定のURLに飛んだときにエラーページを表示させるためにはabort(コード, 文字列)を使用する。 from bottle import route, abort@route('/httpstat')def restricted(): abort(404, "これはテスト")404だけでなく、…
■Error PagesBottleの各エラーページはerrorデコレータを用いてデフォルトのエラーページを上書きする事ができる。from bottle import error@error(404)def error404(error): return 'エラー404'
■Request RoutingBottleのRoutingは@route()を使用する。引数にURLのパスを記載でき、GET,POSTなどの指定も可能。@route()の次の行には割り付ける関数を記載する。@route(path='/hello')def hello(): return "Hello World!"@route('/')@route('/hello/<name>')def </name>…
Webには詳しくはないが、 PythonのWebフレームワークの1つ、Bottleを覚える。 ■使用環境 Python : Python3.4 サーバー : apache2.2 + mod_wsgi OS:Windows7 or Ubunts ■ファイル構成 index.py app.wsgi ■Bottleのインストール <Ubunts> sudo apt-get install pyt</ubunts>…