Python(2.7.9) + Apache/2.2.29 (FreeBSD)の環境でcgiとしてPythonを動かしています。
フレームワークとして、Bottleを使用し、セッション管理ににbeakerを使用し、テンプレートエンジンとしてjinja2を使用しています。
実行しているソースは以下のようになります。
python
1#!/usr/local/bin/python -- 2# -*- coding: utf-8 -*- 3# filename: index.py 4 5import bottle as app 6from beaker.middleware import SessionMiddleware 7 8#jinja2 インポート 9from jinja2 import Environment, FileSystemLoader 10 11#テンプレートファイルの場所を設定 12env = Environment(loader=FileSystemLoader('./tpl/', encoding='utf8')) 13 14session_options = { 15 'session.type': 'file', 16 'session.data_dir': './session/', 17 'session.auto': True, 18} 19app_middlware = SessionMiddleware(app.app(), session_options) 20 21app_session = app.request.environ.get('beaker.session') 22 23@app.route('/index') 24def index(): 25 app_session = app.request.environ.get('beaker.session') 26 app_session['name'] = '変数代入'.decode('utf-8') 27 #使用するテンプレート名を設定 28 tpl = env.get_template('test.tpl.html') 29 html = tpl.render({'name':app_session['name']}) 30 print 'Content-Type: text/html; charset=utf-8\n' 31 print html.encode('utf-8') 32 33 34app.debug(False) 35 36app.run(server='cgi', app=app_middlware, reloader=False, quiet=False, debug=None)
html
1<html> 2<body> 3 4<hr> 5<ul> 6 {{ name }} 7</ul> 8</body> 9</html>
このプログラムを動かすと、Httpのレスポンスヘッダーがテンプレートの内容を出力した下に表示され、ブラウザ上に出力されます。ブラウザに出力されるHTMLは下記のようなものです。
html
1 2<html> 3<body> 4 5<hr> 6<ul> 7 変数代入 8</ul> 9</body> 10</html> 11Status: 200 OK 12Content-Length: 0 13Content-Type: text/html; charset=UTF-8 14Set-cookie: beaker.session.id=c02a517af35644c0826eaa440b416311; Path=/ 15
このHTTPヘッダーを消したいと思っているのですが、どこで出力をする設定をしているのかわかりません。
ご教授いただけると幸いです。
また、今現在共用サーバー上でプログラムを動かしているのですが、
Pythonのプログラムを動かすために、http://aaa.jp/index.py/index
のようなURLでPythonを動かしています。
Options FollowSymLinks RewriteEngine on RewriteCond %{THE_REQUEST} ^.*/index.py RewriteRule ^(.*)index.py$ http://aaa.jp/$1 [R=301,L]
というような.htaccessで、http://aaa.jp/index のURLでアクセスできるようにしたいのですが、
error
1Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden
というようなエラーが表示されます。共用サーバーなのでRewriteできないということだと思うのですが、ほかの方法で上記のようなことを可能にする方法はありますでしょうか。httpd.confとうはいじることができません。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/21 04:05