python-Azure Flask部署-WSGI界面
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-Azure Flask部署-WSGI界面,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2455字,纯文字阅读大概需要4分钟。
内容图文
![python-Azure Flask部署-WSGI界面](/upload/InfoBanner/zyjiaocheng/682/3f35d08f3cc846d1a2184053f0fd12c7.jpg)
我目前正在阅读《 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脚本.
内容总结
以上是互联网集市为您收集整理的python-Azure Flask部署-WSGI界面全部内容,希望文章能够帮你解决python-Azure Flask部署-WSGI界面所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。