windows10部署flaskweb
起因
本来想这⽤django 写⼀个web 应⽤程序,便于管理mongodb的数据。结果django 不直接⽀持mongodb……⼜没时间研究NoSQL。于是想着随便整个api吧……
于是先⽤flask 做个简单的demo 部署到本地试试⽔
简单的demo
from flask import Flask, jsonify
app = Flask(__name__)
tasks = [
{
'id': 1,
'title': u'Buy groceries',
'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
'done': False
},
{
'id': 2,
'title': u'Learn Python',
'description': u'Need to find a good Python tutorial on the web',
'done': False
}
]
@ute('/')
def hello_world():
return jsonify({'task':tasks})
if __name__ == '__main__':
flask下载app.run()
⾛进部署之坑
安装IIS
启⽤CGI
安装Microsoft Web Platform Installer
添加 url 重写(URL Rewrite)和IIS(CGI)
安装 wfastcgi (pip install wfastcgi)
启⽤ wfastcgi
创建fig
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
  <!-- name 和 path 都是项⽬名;scriptProcessor 就是上⾯启动wfastcgi 的返回信息(如上图,画线部分)-->
<add name="DMApi" path="DMApi" verb="*" modules="FastCgiModule" scriptProcessor="e:\demo\fl
ask\dmapi\venv\:\demo\flask\dma      <!-- scriptProcessor 的值来⾃命令⾏⼯具 wfastcgi-enable -->
<add name="FlaskFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="e:\demo\flask\dmapi\venv\:\demo\flask\    </handlers>
<security>
<!-- URL 重写中的特殊字符,⽐如加号+等等 -->
<requestFiltering allowDoubleEscaping="true"></requestFiltering>
</security>
</system.webServer>
<appSettings>
<!-- Required settings -->
<!-- 在这⾥指定Falsk app在模块中的具体位置 -->
<add key="WSGI_HANDLER" value="DMApi.app" />
<add key="PYTHONPATH" value="~/" />
<!-- Optional settings -->
<!-- 需要先创建⽇志⽬录,否则报错 -->
<add key="WSGI_LOG" value="F:\\Demo\\flask\\DMApi\\logs\\web.log" />
<add key="WSGI_RESTART_FILE_REGEX" value="" />
</appSettings>
</configuration>
配置IIS ⽬录及权限
创建⽹站
访问掉坑
⼈家教程⾥写的好好的 “hello ……”
⽽我却是这样的
Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
是这样的……
结果
This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.
终于看到了结果……

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。