Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

python - Apache2 and Flask issue

I try to load my app towards my apache2 server but i keep getting error 500.

File Structure: /var/www/ApproveAndPost:

  • ApproveAndPost.wsgi
  • ApprovePost_Web
  • run.py

/var/www/ApproveAndPost/ApprovePost_Web:

  • forms.py
  • init.py
  • models.py
  • routes.py
  • services.py
  • static
  • templates

Files content: /etc/apache2/sites-available/ApproveAndPost.conf

<VirtualHost *:80>
                ServerName 192.168.170.67
                ServerAdmin [email protected]
                WSGIScriptAlias / /var/www/ApproveAndPost/ApproveAndPost.wsgi
                <Directory /var/www/ApproveAndPost/ApprovePost_Web/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/ApproveAndPost/ApprovePost_Web/static
                <Directory /var/www/ApproveAndPost/ApprovePost_Web/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 File:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/ApproveAndPost")

from ApproveAndPost import app as application
application.secret_key = 'DISISSECRETKEY'

Python Code:

run.py

from ApprovePost_Web import app

if __name__ == "__main__":
    app.run(debug=True)

init.py:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy


app = Flask(__name__)
app.config['SECRET_KEY'] = '#$%^&*'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)


from ApprovePost_Web import routes

if __name__ == "__main__":
    app.run(debug=True)

I think i am mixing up a couple of things ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is essentially that you are installing Flask, and possibly other required libraries, in a virtual environment but the python (wsgi interface) is running with the system python which does not have these extra libraries installed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...