[英]python flask app mod_wsgi/apache
I'm working on getting my python flask app on my linode server. 我正在努力在我的linode服务器上获取我的python flask应用程序。 I've followed a few tutorials to get this configured, but am stuck because when I visit the url, i get this error.
我已经按照一些教程进行了配置,但是由于访问URL时遇到此错误而陷入困境。 "ImportError: No module named ugpromo".
“ ImportError:没有名为ugpromo的模块”。 I've seen other problems like this on stackoverflow, and have tried their solutions, but I still get the same error.
我在stackoverflow上看到了其他类似问题,并尝试了解决方案,但仍然遇到相同的错误。
wsgi file wsgi文件
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/html/codingbybrandon/public_html/ugpromo/")
from ugpromo import app as application
application.secret_key = 'Add your secret key'
init .py 初始化 .py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, I love Digital Ocean!"
if __name__ == "__main__":
app.run()
virtual host file 虚拟主机文件
<VirtualHost *:80>
ServerName ugpromo.codingbybrandon.com
ServerAdmin admin@codingbybrandon.com
ServerAlias www.ugpromo.codingbybrandon.com
WSGIScriptAlias /
/var/www/html/codingbybrandon.com/public_html/ugpromo/ugpromo.wsgi
<Directory /var/www/html/codingbybrandon/public_html/ugpromo/ugpromo/>
Order allow,deny
Allow from all
</Directory>
Alias /static
/var/www/codingbybrandon.com/public_html/ugpromo/ugpromo/static
<Directory
/var/www/codingbybrandon.com/public_html/ugpromo/ugpromo/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
directory listing is as follows 目录清单如下
public_html
ugpromo
__init__.py
ugpromo
static
templates
ugp
ugpromo.wsgi
You've added the outer "ugpromo" directory - the one containing the __init__
file you want to import - to your sys.path. 您已将外部“ ugpromo”目录(包含要导入的
__init__
文件的目录)添加到sys.path。 You need to add the parent of that directory instead: 您需要添加该目录的父目录:
sys.path.insert(0,"/var/www/html/codingbybrandon/public_html/")
(Note, however, you really shouldn't be putting code under public_html. Place it somewhere else.) (但是请注意,您实际上不应该将代码放在public_html下。将其放置在其他位置。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.