我最近安装了apache服务器来服务windows上的flask应用程序,让我来告诉你我的安装。
1.我已经通过apache lounge下载了apache。已经将其解压到C:\Apache24。
1.我确实在虚拟python 3.7.7中安装了mod_wsgi
1.在httpd.conf文件中复制mod_wsgi配置
1.我在Apache的conf目录中创建了my_app.conf
但是我在apache的error.log文件中得到以下错误...
[Fri Nov 11 18:44:00.985814 2022] [wsgi:error] [pid 9456:tid 1396] [client 127.0.0.1:58152] mod_wsgi (pid=9456): Exception occurred processing WSGI script 'J:/tools/pipecrew/ashish/workspace/tools/wsgi_scripts/shotgrid_ami_handler.wsgi'.
[Fri Nov 11 18:44:00.985814 2022] [wsgi:error] [pid 9456:tid 1396] [client 127.0.0.1:58152] TypeError: 'module' object is not callable\r
[Fri Nov 11 18:44:01.020776 2022] [wsgi:error] [pid 9456:tid 1392] [client 127.0.0.1:58153] mod_wsgi (pid=9456): Exception occurred processing WSGI script 'J:/tools/pipecrew/ashish/workspace/tools/wsgi_scripts/shotgrid_ami_handler.wsgi'., referer: http://fpservices.in/boom
[Fri Nov 11 18:44:01.020776 2022] [wsgi:error] [pid 9456:tid 1392] [client 127.0.0.1:58153] TypeError: 'module' object is not callable\r, referer: http://fpservices.in/boom
下面是我的其他片段
- Apache httpd.conf文件
LoadFile "J:/tools/rez_packages/python/3.7.7/platform-windows/python37.dll"
LoadModule wsgi_module "D:/virtual_python/python-3/mod_wsgi/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "D:/virtual_python/python-3/mod_wsgi"
# Include Flask File
Include conf/shotgrid_ami_handler.conf
- Apache的conf目录中的我的flask应用程序conf文件
<VirtualHost *:80>
ServerName fpservices.in
WSGIScriptAlias / J:/tools/pipecrew/ashish/workspace/tools/wsgi_scripts/shotgrid_ami_handler.wsgi
<Directory J:/tools/pipecrew/ashish/workspace/tools/shotgrid_ami_handler>
WSGIScriptReloading On
Require all granted
</Directory>
</VirtualHost>
1.和我的wsgi文件。
import sys
sys.path.insert(0, 'J:\\tools\\pipecrew\\ashish\\workspace\\tools')
from shotgrid_ami_handler import app as application
1.最后是我的酒瓶应用程序。
from flask import Flask, request, Response
app = Flask(__name__)
@app.route('/boom', methods=['GET', 'POST'])
def boom():
return 'boom!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=4576, debug=True)
有人能指出为什么我在这里得到“模块”对象是不可调用的错误吗?
我正在尝试通过Apache服务器执行flask routing函数,但是我在apache error.log文件中没有得到足够的错误信息,甚至没有尝试什么。
1条答案
按热度按时间ndasle7k1#
这是一个非常愚蠢的错误。在我的wsgi脚本中,我导入了我的主flask模块作为应用程序对象,而不是模块内部的Flask对象。所以我的flask应用程序有一个模块
app
,其中包含Flask对象app
。所以不要这样做我应该这么做的