windows 10 部署flask web

來源:互聯網
上載者:User

標籤:spec   ping   資料   restart   exp   重寫   access   locking   uri   

起因

本來想這用django 寫一個web 應用程式,便於管理mongodb的資料。結果django 不直接支援mongodb……又沒時間研究NoSQL。於是想著隨便整個api吧……

於是先用flask 做個簡單的demo 部署到本地試試水

簡單的demo
from flask import Flask, jsonifyapp = 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/    借鑒一下吧

  • 安裝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 ……”

而我卻是這樣的

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.  

Add Application Development from the Features! Remember to add the 4.5 stuff if you need it

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

 終於看到了結果……

 

windows 10 部署flask web

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.