【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>
その管理方法を使用すれば良い。
■mod_wsgi
<Ubunts>
-
<Windows7>
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
上記から対象のファイルをダウンロードする。
mod_wsgi.soファイルをC:\Apache2.2\modulesに放り込む。
■httpd.conf
apacheの設定。
これをしておかないと、**.pyを更新してもapacheを再起動しないと変更が反映されない。
ggxrdというフォルダはご愛嬌。
■app.wsgi
wsgiファイルの設定
■index.py
Bottleの「Example: “Hello World” in a bottle」の通りにほぼ書く。
apacheを起動し、
「http://localhost:8080/hello/word」にアクセスする。
「Hello world!」
と表示されれば成功。
Bottleへの第一歩。
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 python-bottle<Windows7>
pip install bottleモジュール管理している人は
その管理方法を使用すれば良い。
■mod_wsgi
<Ubunts>
-
<Windows7>
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
上記から対象のファイルをダウンロードする。
mod_wsgi.soファイルをC:\Apache2.2\modulesに放り込む。
■httpd.conf
apacheの設定。
LoadModule wsgi_module modules/mod_wsgi.soMaxRequestsPerChild 1は開発用のため。
WSGIScriptAlias / C:/webserver/ggxrd/app.wsgi
WSGIScriptReloading On
MaxRequestsPerChild 1
<Directory "C:/webserver/ggxrd">
#SetHandler wsgi-script
Order deny,allow
Allow from all
</Directory>
これをしておかないと、**.pyを更新してもapacheを再起動しないと変更が反映されない。
ggxrdというフォルダはご愛嬌。
■app.wsgi
wsgiファイルの設定
# coding:utf-8
import sys, os
dirpath = os.path.dirname(os.path.abspath(__file__))
sys.path.append(dirpath)
os.chdir(dirpath)
import bottle
import index
application = bottle.default_app()
■index.py
Bottleの「Example: “Hello World” in a bottle」の通りにほぼ書く。
# coding:utf-8
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
if __name__ == '__main__':
run(host='127.0.0.1', port=8080, debug=True, reloader=True)
apacheを起動し、
「http://localhost:8080/hello/word」にアクセスする。
「Hello world!」
と表示されれば成功。
Bottleへの第一歩。