librelist archives

« back to archive

Problems with sqlite and webfaction.

Problems with sqlite and webfaction.

From:
Viktor Forsman
Date:
2011-10-10 @ 11:32
Hi. I have written a small webapp using the Flask framework as a toy
for me and a couple of friends. It uses forms which stores data in a
sqlite databse and then uses that data to produce graphs.

The application get's online but when trying to enter data into the
database I get internal server error and in the user log it says:
'Operational Error: No such table: tablename'.

I have created the database and set rw access to groups. The complete
code is hosted https://github.com/monostop/workout_web and relevant (I
guess) lines:

def connect_db():
    return sqlite3.connect(app.config['DATABASE'])

def init_db():
    with closing(connect_db()) as db:
        with app.open_resource('schema.sql') as f:
            db.cursor().executescript(f.read())
        db.commit()

@app.before_request
def before_request():
    g.db = connect_db()

@app.teardown_request
def teardown_request(exception):
    g.db.close()

@app.route('/')
def main_page():
    return render_template('main.html')

@app.route('/add', methods = ['POST'])
def add():
    # Need to change to current user.
    try:
        if bool(request.form['date']): # if user submits empty string
dont insert anything into db.
            dateutil.parser.parse(request.form['date'])
            g.db.execute('INSERT INTO '+session['user']+ '(date,value)
VALUES (?,?)', \
                             [request.form['date'],request.form['value']] )
            g.db.commit()
    except ValueError:
        # need to print some error message.
        pass
    return redirect(url_for('main_page'))

I'm very new to all these things so all ideas and pointers are highly
appreciated.

Re: [flask] Problems with sqlite and webfaction.

From:
Ron DuPlain
Date:
2011-10-10 @ 13:13
Hi,

On Mon, Oct 10, 2011 at 7:32 AM, Viktor Forsman
<viktor.forsman@gmail.com> wrote:
> Hi. I have written a small webapp using the Flask framework as a toy
> for me and a couple of friends. It uses forms which stores data in a
> sqlite databse and then uses that data to produce graphs.
>
> The application get's online but when trying to enter data into the
> database I get internal server error and in the user log it says:
> 'Operational Error: No such table: tablename'.

This line of configuration is suspect:

DATABASE = "workouts.db"
https://github.com/monostop/workout_web/blob/master/workout_web.py#L10

This assumes workouts.db is in the working directory of the running
process.  Is it?  Use a full file path if you can.

-Ron

Re: [flask] Problems with sqlite and webfaction.

From:
Viktor Forsman
Date:
2011-10-10 @ 13:24
Thanks for the reply. Using the full path made it work correctly!

2011/10/10 Ron DuPlain <ron.duplain@gmail.com>:
> Hi,
>
> On Mon, Oct 10, 2011 at 7:32 AM, Viktor Forsman
> <viktor.forsman@gmail.com> wrote:
>> Hi. I have written a small webapp using the Flask framework as a toy
>> for me and a couple of friends. It uses forms which stores data in a
>> sqlite databse and then uses that data to produce graphs.
>>
>> The application get's online but when trying to enter data into the
>> database I get internal server error and in the user log it says:
>> 'Operational Error: No such table: tablename'.
>
> This line of configuration is suspect:
>
> DATABASE = "workouts.db"
> https://github.com/monostop/workout_web/blob/master/workout_web.py#L10
>
> This assumes workouts.db is in the working directory of the running
> process.  Is it?  Use a full file path if you can.
>
> -Ron
>