I’m trying to set up a simple website using Flask, wsgi, and apache2. I’m getting the following error trying to import from site.py into site.wsgi:
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] mod_wsgi (pid=15170): Target WSGI script '/home/www/site/site.wsgi' cannot be loaded as Python module.
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] mod_wsgi (pid=15170): Exception occurred processing WSGI script '/home/www/site/site.wsgi'.
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] Traceback (most recent call last):
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] File "/home/www/site/site.wsgi", line 1, in <module>
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] from site import app as application
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] ImportError: cannot import name app
Here is my site.py:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home_page():
return render_template('index.html')
app.debug = True
if __name__ == '__main__'
app.run()
Here is my site.wsgi:
from site import app as application
And here is my apache config:
<VirtualHost *:80>
ServerAdmin my@email.here
ServerName mywebsite.here
DocumentRoot /home/www/site
WSGIDaemonProcess site user=${APACHE_RUN_USER} group=${APACHE_RUN_GROUP} threads=5
WSGIScriptAlias / /home/www/site/site.wsgi
<Directory /home/www/site>
WSGIProcessGroup site
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
I’ve searched around for a while trying to figure this out but I’m stumped. I’m also fairly new to web design, so it could be something silly. Thanks in advance.
Found the answer – as Audrius said in the comments, it was a conflict because I named the file site.py. I changed it to mysite.py everywhere necessary and added the following to mysite.wsgi (formerly site.wsgi):