2015-02-01から1ヶ月間の記事一覧

【Python】【Bottle】 Query Variables

■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)…

【Perl6】 yukicoder

yukicoderにPerl6を入れてもらった。たまに使ってみる感じ。速度的にはorzPerl6は正式リリースされたらちゃんと使ってみる感じ。それまではやっぱりPython。標準入力は# 単行get()# 複数行for lines() {}# 1行に複数個のINPUTmy @array = get().split(" ");s…

【Python】【Bottle】 Cookie

■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 …

悲報

Bottleで遊ぶもInternal Server Errorが発生しログと睨めっこするも解決せず、辛いorz

【Python】【Bottle】 HTTP Errors and Redirects

■HTTP Errors and Redirectsということで、特定のURLに飛んだときにエラーページを表示させるためにはabort(コード, 文字列)を使用する。 from bottle import route, abort@route('/httpstat')def restricted(): abort(404, "これはテスト")404だけでなく、…

【Python】【Bottle】 Error Pages

■Error PagesBottleの各エラーページはerrorデコレータを用いてデフォルトのエラーページを上書きする事ができる。from bottle import error@error(404)def error404(error): return 'エラー404'

【Python】【Bottle】 Request Routing

■Request RoutingBottleのRoutingは@route()を使用する。引数にURLのパスを記載でき、GET,POSTなどの指定も可能。@route()の次の行には割り付ける関数を記載する。@route(path='/hello')def hello(): return "Hello World!"@route('/')@route('/hello/<name>')def </name>…

【Python】【Bottle】 初めてのBottle

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>…