[英]Flask and wsgi, ImportError: cannot import name app
Hi sorry to bother again, I'm working on my first flask project, very simple one. 嗨,抱歉再次打扰,我正在做我的第一个烧瓶项目,非常简单。
I'm deploying my site on Digital Ocean, ubuntu server. 我正在ubuntu服务器Digital Ocean上部署我的网站。 And I complied with its instructions .
而且我遵守了它的指示 。
Problem : When I tried to open the site in browser, it came with 500 error. 问题 :当我尝试在浏览器中打开网站时,它出现了500错误。 Then I looked up the apache error log to find the following sentences.
然后,我查看了apache错误日志以查找以下句子。
Error log: 错误日志:
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] mod_wsgi (pid=27835): Target WSGI script '/var/www/qianshan/qianshan.wsgi' cannot be loaded as Python module.
[2014年12月31日星期三07:45:49] [错误] [客户端112.64.71.131] mod_wsgi(pid = 27835):目标WSGI脚本'/var/www/qianshan/qianshan.wsgi'无法作为Python模块加载。
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] mod_wsgi (pid=27835): Exception occurred processing WSGI script '/var/www/qianshan/qianshan.wsgi'.
[2014年12月31日星期三07:45:49] [错误] [客户端112.64.71.131] mod_wsgi(pid = 27835):处理WSGI脚本'/var/www/qianshan/qianshan.wsgi'时发生异常。
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] Traceback (most recent call last):
[2014年12月31日星期三07:45:49] [错误] [客户端112.64.71.131]追溯(最近一次通话为最后一次):
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] File "/var/www/qianshan/qianshan.wsgi", line 7, in
[2014年12月31日星期三07:45:49] [错误] [客户端112.64.71.131]文件“ /var/www/qianshan/qianshan.wsgi”,第7行,
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] from qianshan import app as application
[2014年12月31日星期三07:45:49] [错误]来自千山导入应用程序的[客户端] [客户端112.64.71.131]
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] ImportError: cannot import name app
[2014年12月31日星期三07:45:49] [错误] [客户端112.64.71.131] ImportError:无法导入名称应用
Tree structure of the project 项目的树形结构
spark@Qianshan:/var/www/qianshan$ tree -L 2
.
├── qianshan
│ ├── config.ini
│ ├── qianshan.py
│ ├── static
│ ├── templates
│ └── venv
└── qianshan.wsgi
Virtual Host configuration 虚拟主机配置
<VirtualHost *:80>
ServerName qianshan.co
ServerAdmin spark@qianshan.co
WSGIScriptAlias / /var/www/qianshan/qianshan.wsgi
<Directory /var/www/qianshan/qianshan/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/qianshan/qianshan/static
<Directory /var/www/qianshan/qianshan/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
wsgi gi
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/qianshan/")
from qianshan import app as application
application.secret_key = 'Add your secret key'
.py file .py文件
# Filename: qianshan.py
# encoding: utf-8
import ConfigParser
import codecs
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/')
def index():
block_list = getBlockList()
website_dict = getWebsiteDict()
return render_template('index.html', block_list=block_list, website_dict=website_dict)
...
...
if __name__ == '__main__':
app.run()
Happy new year to all if you are lucky enough to see this bottom line ^_^ 祝大家新年快乐,如果您有幸看到这一底线^ _ ^
create a /var/www/qianshan/ init .py file as show below: 创建一个/ var / www / qianshan / init .py文件,如下所示:
from flask import Flask
app = Flask(__name__)
import quianshan.quianshan #This is your view file.
Then remove this line from quianshan.py 然后从quianshan.py删除此行
app = Flask(__name__)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.