-1

I want to connect to a sqlite database. how to modify the sqlite3.connect("PATH") statement if the database file resides in the app_name/data/database_file.db

I tried many variations ,but all causes internal server error 500.

My current code looks like this (its just a dummy code i'm using for testing)

from flask import render_template,request,g
from app import app
import sqlite3
import os


@app.before_request
def before_request():
    g.db =    sqlite3.connect(os.path.join(os.environ.get('OPENSHIFT_DATA_DIR'), 'torrents_small.db'))

@app.teardown_request
    def close_connection(exception):
    db = getattr(g, 'db', None)
   if db is not None:
       db.close()

@app.route('/')
    def index():
    cur = g.db.cursor()
    cur.execute("select * from torrents_small")
    return "hello"
SATW
  • 85
  • 1
  • 8

1 Answers1

0

Have you tried your code without connecting to a database to see if that is causing your 500. The other things is that Flask swallows exceptions by default

this example shows you how to get Flask to show exceptions

https://github.com/thesteve0/openshift-mongo-flask-example/blob/master/wsgi/myflaskapp.py

TheSteve0
  • 3,530
  • 1
  • 19
  • 25
  • YEs i did try that, i found out that the exception is caused by the statement `cur.execute("select * from torrents_small")` . I found this by adding statements one by one to the the minimal app . – SATW Jan 21 '15 at 19:14
  • What is the exception error with that statement? – TheSteve0 Jan 22 '15 at 18:39