zoukankan      html  css  js  c++  java
  • windows 10 部署flask web

    起因

    本来想这用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
        }
    ]
    
    @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:demoflaskdmapivenvscriptspython36.exe|e:demoflaskdmapivenvlibsite-packageswfastcgi.py" resourceType="File" /> <!-- scriptProcessor 的值来自命令行工具 wfastcgi-enable --> <add name="FlaskFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="e:demoflaskdmapivenvscriptspython36.exe|e:demoflaskdmapivenvlibsite-packageswfastcgi.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……

     终于看到了结果……

  • 相关阅读:
    js 类型转换学习
    Prototypes in Javascript 收集.__proto__
    不想说作用域scope,因为是scopeTree,
    在家学习 利器 记录每日点滴
    图片切换特效的分析和学习
    js 无缝滚动效果学习
    MySQL 在高并发下的 订单撮合 系统使用 共享锁 与 排他锁 保证数据一致性
    (二)区块链的共识算法:PoS 及其 例子 代码 实现
    以太坊: ETH 发送交易 sendRawTransaction 方法数据的签名 和 验证过程
    Golang 的 协程调度机制 与 GOMAXPROCS 性能调优
  • 原文地址:https://www.cnblogs.com/taoyoung/p/8797455.html
Copyright © 2011-2022 走看看