WebFaction
Community site: login faq

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 0log it says: 'Operational Error: No such table: tablename'.

I have created the database and set rw access to groups. The complete code is hosted here 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('/add', methods = ['POST'])
def add():

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.

asked 10 Oct '11, 06:22

monostop
515
accept rate: 0%

edited 10 Oct '11, 06:24


Hi,

Make sure that you have the full path (not relative) to the database filename in app.config['DATABASE']. Using a relative path can cause such a problem sometimes.

If this doesn't fix the problem, please submit a ticket about this, so we can test and reproduce the problem. Thanks.

permanent link

answered 10 Oct '11, 06:54

todork
1.2k4
accept rate: 34%

edited 10 Oct '11, 06:54

Thanks! That solved the problem :)

(10 Oct '11, 07:14) monostop

You are most welcome!

(10 Oct '11, 07:18) todork
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×44
×11

question asked: 10 Oct '11, 06:22

question was seen: 4,893 times

last updated: 10 Oct '11, 07:18

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM