我在http://localhost/service/payrollapi中托管了我的Python Flask API-如何在app.run()方法中指定此URL。但是它失败,并且有时会返回HTTP状态代码404,有时会返回500。我不知道该怎么办。
MYLAPTOP (IIS Server)
|
|____Sites
|
|____Default Web Site (Website)
|
|____service (Virtual Directory)
|
|____payrollapi (Application)
payrollapi的URL为http://localhost/service/payrollapi/
我配置了wfastcgi和FastCGI设置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="FlaskHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\annaconda\envs\payroll\python.exe|c:\annaconda\envs\payroll\lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
</handlers>
</system.webServer>
<appSettings>
<add key="WSGI_HANDLER" value="payroll.app" />
<add key="PYTHONPATH" value="C:\inetpub\wwwroot\service\payrollapi" />
</appSettings>
</configuration>
Flask API脚本: payroll.py
from flask import Flask
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def notes_list():
return "Welcome to Payroll !"
if __name__ == "__main__":
app.run("localhost",80,debug=True)
我不知道如何指定网址(即http://localhost/service/payrollapi
)而不是'localhost'
我不是在问虚拟路径。问题的实质是如何在主要网站的子目录中部署Flask API,以及如何在我们当前的Flask API配置中配置URL。