简体   繁体   中英

Flask + apache Internal Server Error when making request or database

I'm using apache with flask and when opening /login (I use database here) i get Internal server Error As database im using sqlite and python library sqlite3

DATABASE = '../../var/www/flask/database'

connecting database function :

def connect_db():
    return sqlite3.connect(DATABASE)

login code

@app.route('/login', methods=['POST'])
def login():
    if request.cookies.get("name"):
        return render_template("home.html",name=request.cookies.get('name'))
    g.db = connect_db() 
    cur = g.db.execute('SELECT email, password, name, confirmed FROM users')
    for row in cur.fetchall(): 
            if row[0] == request.form['email'] and row[1] ==   hashlib.sha224(request.form['password']).hexdigest() and row[3] == 1:
                resp = make_response(redirect(host + "/home"))
                resp.set_cookie("name",row[2])
                resp.set_cookie("password",row[1])
                return resp
    return redirect(host)

here is my .wsgi code

import sys

sys.path.insert(0, '/var/www/flask/')

from routes import app as application

and here is my app tree
flask - static - (css js etc.)
- templates - (jinja2 template)
- database.db
- min.wsgi
- routes.py (app)

here is routes.com.conf

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName server.test
    WSGIScriptAlias / /var/www/flask/min.wsgi
    <Directory /var/www/flask/>
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

You need to use an absolute path for your DATABASE value.

The mod_wsgi module will set a different current working directory for your app, one you most likely do not have access to. Even if you did give your Apache process write access to that directory, you don't want to end up changing a seemingly harmless setting elsewhere for it all to stop working again.

Maybe because of wrong indentation in login function? It would caused some very other error log probably, but it's my first guess when I'm looking at code formatted in wrong way (even if it's just wrong copy-paste).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM