大佬教程收集整理的这篇文章主要介绍了Azure Flask部署-WSGI界面,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
经过一番令人不安的拍摄后,我能够找到解决问题的方法,但不幸的是,无法确切地找出问题所在。
基本上,我经历了在VS2015中从头开始重建测试项目的过程(Python-> Azure Cloud service-> Flask Web Role),并且这次可以使用7a测试项目并在Azure中运行该解决方案来获得可行的解决方案模拟器,然后将其成功发布为Azure Web App。
我相信我的问题可能是由以下问题之一引起的:
if __name__ == '__main__':
app.run()
这可能也有帮助。
我希望这可以帮助其他可能遇到类似问题的人。
我目前正在阅读《 FlaskWeb开发,用Python开发Web应用程序》一书,并且在确定应放置WSGI接口的位置时遇到一些问题,以便可以将其部署到Azure Webservice。作为参考,
为了尝试解决问题出在哪里,我在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',PORT)
当我尝试在Azure仿真器中运行它时收到以下错误。
AttributeError: 'module' object has no attribute 'wsgi_app'
我怀疑我没有将wsgi_app变量放置在正确的位置,但是我无法弄清楚应该将其放置在什么位置。
任何帮助将是极大的赞赏。
以上是大佬教程为你收集整理的Azure Flask部署-WSGI界面全部内容,希望文章能够帮你解决Azure Flask部署-WSGI界面所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。