Reputation: 1246
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>
Upvotes: 1
Views: 1487
Reputation: 1124658
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.
Upvotes: 2
Reputation: 1186
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).
Upvotes: 0