Twilio の Restful 拡張機能を使用して、Flask で API を作成しました。Flask の開発サーバーでは、すべてが完全に機能します。ただし、アプリを Apache と mod_wsgi に移行すると、一部のルートが機能しなくなりました
アパッチ構成:
Listen 1337
<VirtualHost *:1337>
ServerName layer
ServerAdmin webmaster@localhost
DocumentRoot /var/www/layer
WSGIDaemonProcess layer user=this_is_me group=www-data threads=5
WSGIScriptAlias / /var/www/layer/app.wsgi
WSGIScriptReloading On
<Directory /var/www/layer>
WSGIProcessGroup layer
WSGIApplicationGroup %{GLOBAL}%
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
app.wsgi で:
from src import app
application = app.create_app()
app.py で:
#!flask/bin/python
from flask import Flask, request, jsonify, Response
from flask.ext.restful import Resource, Api
from view import treeView, createBranchView, branchView, lineView, bulkView
def create_app():
app = Flask(__name__)
api = Api(app, catch_all_404s=True)
logging.basicConfig(filename=os.path.abspath('exlayer.log'), level=logging.DEBUG)
#Some stand alone routes
@app.route('/')
def index():
### Some code here ###
return jsonify({'status': 200, 'success':True})
@app.route('/create/', methods = ['POST'])
def create_tree():
### Some more code ###
return jsonify(dict(status=200, success=True))
## The rest of the routes
api.add_resource(treeView.dataTree, '/<tree_name>/')
api.add_resource(lineView.lineData, '/<tree_name>/line/<line_id>/')
api.add_resource(bulkView.bulkData, '/<tree_name>/bulk/<bulk_id>/')
api.add_resource(createBranchView.createBranch, '/<tree_name>/branch/')
api.add_resource(branchView.branchData, '/<tree_name>/branch/<branch_identifier>/')
app.config.from_pyfile('../config/config.py')
return app
バルクビューで
ここで興味深いことに、このルートに get リクエストを送信すると、Method Not Allowed 405 エラーが発生します。削除リクエストを送信すると、正常に機能します。ほとんど同じコードが lineView で問題なく実行されます。
from flask import Flask, request, jsonify, Response
from flask.ext.restful import Resource, Api
from src import helper
class bulkData(Resource):
def get(self, tree_name, bulk_id):
## Some code here ##
return jsonify({'status': 200, 'success':True})
def delete(self, tree_name, bulk_id):
## Some code here ##
return jsonify({'status': 200, 'success':True})
branchView で
ブランチ 404s に関するいずれかのルートへの要求。ファイルのアクセス許可を確認し、クラスを別々のファイルに分割しようとしました。何が悪いのかわからない:(