windows 10 部署flask web

原由

原本想這用django 寫一個web 應用程序,便於管理mongodb的數據。結果django 不直接支持mongodb……又沒時間研究NoSQL。因而想着隨便整個api吧……python

因而先用flask 作個簡單的demo 部署到本地試試水web

簡單的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
    }
]

@app.route('/')
def hello_world():
    return jsonify({'task':tasks})


if __name__ == '__main__':
    app.run()

 走進部署之坑

網上五花八門的部署blog……各類轉載…… http://python.jobbole.com/87655/    借鑑一下吧mongodb

  • 安裝IIS
  • 啓用CGI
  • 安裝Microsoft Web Platform Installer
  • 添加 url 重寫(URL Rewrite)和IIS(CGI)
  • 安裝 wfastcgi (pip install wfastcgi)
  • 啓用 wfastcgi

     

  • 建立web.config
    <?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\flask\dmapi\venv\scripts\python36.exe|e:\demo\flask\dmapi\venv\lib\site-packages\wfastcgi.py" resourceType="File" /> <!-- scriptProcessor 的值來自命令行工具 wfastcgi-enable --> <add name="FlaskFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="e:\demo\flask\dmapi\venv\scripts\python36.exe|e:\demo\flask\dmapi\venv\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" /> </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 ……」django

而我倒是這樣的json

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".flask

是這樣的……api

 

 結果

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.   app

Add Application Development from the Features! Remember to add the 4.5 stuff if you need itasp.net

解決方案就是安裝一下asp.net……ide

 終於看到告終果……

相關文章
相關標籤/搜索