python - 如何在 Webfaction 上部署 Flask 应用程序?

标签 python flask

有人知道如何在 Webfaction 上部署一个简单的 Flask 应用程序吗? 我知道 Webfaction 支持 mod_wsgi 并且我阅读了 Flask 网站上的指南,但我仍然无法让我的应用程序运行。有人有工作配置吗?

更新 以回答 Graham Dumpleton 的评论。

我收到 500 内部服务器错误。 Apache 没有在日志中显示任何错误。 WSGI 脚本已执行,似乎可以正确创建应用程序,但我一直收到 500 错误。

谢谢。

最佳答案

我通过以下过程让它工作:

  • 创建名为“myapp”的应用程序,类型为 mod_wsgi 3.3/Python 2.7。 Webfaction 将创建以下文件夹:

    myapp
         |- apache2
         |- htdocs
    
  • Webfaction 还会在您的htdocs 目录中自动创建一个简单的脚本index.py。检查示例脚本是否可以访问您新创建的应用程序的根目录(要在 Webfaction 上精简,您需要将应用程序“安装”到网站上)。如果一切正常,修改脚本删除内容并添加:

    from myapp import app as application
    
  • apache2/conf/httpd.conf 中添加以下行:

    WSGIPythonPath /home/username/webapps/myapp/htdocs/
    #If you do not specify the next directive the app *will* work but you will
    #see index.py in the path of all subdir
    WSGIScriptAlias / /home/username/webapps/myapp/htdocs/index.py
    
    
    <Directory /home/username/webapps/myapp/htdocs>
        AddHandler wsgi-script .py
        RewriteEngine on
        RewriteBase /
        WSGIScriptReloading On
    </Directory>
    
  • 重启apache2

关于python - 如何在 Webfaction 上部署 Flask 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3277657/

相关文章:

python - 如何控制 Scapy 中协议(protocol)头/消息的大小?

python - Keras中WARP loss的实现

python - 将包含整数的元组解压到列表中

python - 扩展未出现在 Flask Python 中的基本模板

python - 尝试使用flask-security注册用户时出现"TypeError: hashpw() argument 1 must be str, not bytes"

python - 如何将数据框中的 2 行连接到新数据框中的 1 行?

python - 带有验证码表单的夹层中的 CSRF token 验证失败

python - Flask 提交表单时返回 'Method not allowed'

python-3.x - 在 Mac (OS High Sierra) 上安装 Flask-mysqldb (python 3) 时出错

docker - 从Docker容器访问Google OAuth时出错:专用IP需要device_id和device_name