ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python-Azure Flask部署-WSGI界面

2019-10-27 22:55:11  阅读:387  来源: 互联网

标签:azure visual-studio-2015 flask ptvs python


我目前正在阅读《 Flask Web开发,用Python开发Web应用程序》一书,并且在确定应放置WSGI接口的位置时遇到一些问题,以便可以将其部署到Azure Web Service.供参考,我目前在第7章,并且我正在处理的这段代码的副本可以在https://github.com/miguelgrinberg/flasky/tree/7a中找到.

为了尝试解决问题出在哪里,我在Visual Studio中使用Flask创建了一个测试Azure云服务,该服务可以在Azure模拟器中完美运行.以下代码是app.py文件的副本.

"""
This script runs the application using a development server.
It contains the definition of routes and views for the application.
"""

from flask import Flask
app = Flask(__name__)

# Make the WSGI interface available at the top level so wfastcgi can get it.
wsgi_app = app.wsgi_app

@app.route('/')
def hello():
    """Renders a sample page."""
    return "Hello World!"

if __name__ == '__main__':
    import os
    HOST = os.environ.get('SERVER_HOST', 'localhost')
    try:
        PORT = int(os.environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555
    app.run(HOST, PORT)

此处的关键行是wfastcgi选择的wsgi_app属性的声明.但是,当我尝试将其插入以下代码(供参考的代码为manage.py)并稍作更改以使用测试项目设置运行时

#!/usr/bin/env python
import os
from app import create_app, db
from app.models import User, Role
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)


def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)


@manager.command
def test():
    """Run the unit tests."""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)

# Make the WSGI interface available at the top level so wfastcgi can get it.
wsgi_app = app.wsgi_app

if __name__ == '__main__':
    HOST = os.environ.get('SERVER_HOST', 'localhost')
    try:
        PORT = int(os.environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555
    app.run(HOST, PORT)

当我尝试在Azure仿真器中运行它时收到以下错误.

AttributeError: 'module' object has no attribute 'wsgi_app'

我怀疑我没有将wsgi_app变量放置在正确的位置,但是我无法弄清楚应该在哪里放置它.

任何帮助将是极大的赞赏.

解决方法:

您是否考虑过使用Web应用程序来启动和运行Flask?这是有关如何在Web应用程序上部署Flask的综合指南:
https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-create-deploy-flask-app/

它将自动为您设置一个站点并处理web.config和快速cgi脚本.

标签:azure,visual-studio-2015,flask,ptvs,python
来源: https://codeday.me/bug/20191027/1948112.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有