Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...