使用Dreamhost共享主机上的Passenger WSGI无法运行Flask

编程入门 行业动态 更新时间:2024-10-03 23:23:06
本文介绍了使用Dreamhost共享主机上的Passenger WSGI无法运行Flask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在Dreamhost共享服务器上运行一个Flaskhello world应用程序,遵循他们的wiki ,但我没有任何运气。

我的Flask应用程序是来自

> from flask import Flask app = Flask(__ name__) @ app.route('/') def hello_world(): return'Hello World! ' if __name__ =='__main__': app.run()

根据DH wiki的说明,我在一个名为mysite的文件夹中有一个名为hello.py的文件。我的passenger_wsgi.py文件是:

import sys,os INTERP = os.path.join(os.environ如果sys.exe可用!= INTERP: os.execl(INTERP,INTERP,* sys.argv) $'$'$'$' b sys.path.append(os.getcwd())$ b $ mysite从应用程序导入hello

<我已经尝试在Python控制台中运行这些命令,并且最后一次导入行失败,直到我将 __ init __。py 文件添加到mysite目录。 b $ b

当我尝试访问网站时,我得到了一个500错误(不幸的是,在日志中没有任何东西,除非它们在日志中,我无法得到,因为这是一个共享服务器。 ..)。

由于这是最基本的设置(即从wiki复制和粘贴),我不禁感到,我失去了一些东西真的很简单。或者也许这是不可能在共享服务器上?

解决方案

回答我自己的问题意味着我正在跟自己说话吗?

无论如何 - 我似乎已经修好了。而不是找到一个很好的有用的错误消息,我一次又一次地经历了所有的步骤,事实证明这是 passenger_wsgi.py 文件中的导入错误。由于该应用程序位于 mysite 子目录中,因此:

来自mysite import hello as application

应该已经(实际上现在是):

from mysite.hello导入应用程序作为应用程序

它的工作原理。这很好。

I'm trying to get a Flask "hello world" application working on a Dreamhost shared server, following the instructions on their wiki, but I'm not having any luck.

My Flask application is the "hello world" one from the Flask quickstart guide:

from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()

Which I've got in a file called "hello.py" in a folder called mysite, as per the DH wiki instructions. My passenger_wsgi.py file is:

import sys, os INTERP = os.path.join(os.environ['HOME'], 'flask_env', 'bin', 'python') if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv) sys.path.append(os.getcwd()) from mysite import hello as application

I've tried running the commands in a Python console, and last import line failed until I added the __init__.py file to the mysite directory.

When I try and access the website I just get a 500 error (and nothing in the logs unfortunately, unless they're in logs I can't get to as this is a shared server...).

As this is the most basic of setups (i.e., copied and pasted from a wiki), I can't help feeling that I'm missing something really simple. Or perhaps this isn't possible on a shared server?

解决方案

Does answering my own question mean I'm talking to myself?

Anyway - I seem to have fixed it. Rather than find a nice helpful error message, I went through all the steps again one at a time, and it turns out it was an import error in the passenger_wsgi.py file. As the app is in the mysite subdirectory, the line:

from mysite import hello as application

should have been (and in fact, now is):

from mysite.hello import app as application

And it works. Which is nice.

更多推荐

使用Dreamhost共享主机上的Passenger WSGI无法运行Flask

本文发布于:2023-11-02 06:40:35,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主机   Dreamhost   Passenger   Flask   WSGI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!