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. And I complied with its instructions.
Problem: When I tried to open the site in browser, it came with 500 error. Then I looked up the apache error log to find the following sentences.
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.
[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'.
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] Traceback (most recent call last):
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] File "/var/www/qianshan/qianshan.wsgi", line 7, in
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] from qianshan import app as application
[Wed Dec 31 07:45:49 2014] [error] [client 112.64.71.131] ImportError: cannot import name app
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
#!/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
# 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 ^_^