2013-01-31 2 views
1

데이터베이스의 필드 값을 사용하는 RadioField 양식 항목이 있습니다.플라스크 WTF 양식이 sqlite3 데이터베이스로 업데이트되지 않습니다.

데이터베이스가 생성되지 않은 경우 해당 페이지로 이동하여 해당 양식을로드 할 때 데이터베이스에만 액세스해야하지만 플라스크 웹 서버를 시작할 수 없습니다.

웹 서버가 실행되는 동안 데이터베이스를 업데이트하면 새 데이터베이스 정보가있는 양식이 표시되지 않습니다.

플라스크 웹 서버를 다시 시작할 때까지.

페이지를 방문 할 때 양식이 강제로 데이터베이스에서 해당 값을 다시로드하도록하려면 어떻게 가져올 수 있습니까?

또한 데이터베이스를 삭제할 수 있고 Flask 웹 서버가 계속 실행되고 RadioField가 여전히 표시되므로 RadioField의 값을 메모리에 저장한다는 것이 확실합니다.

내가 sqlite3를 데이터베이스를 사용하고 읽고 APSW로에 쓰고 있어요 (또 다른 파이썬 sqlite3를 래퍼)

이 여기 내보기 내 양식

class DatabaseForm(Form): 
    listOfRows = db.getDatabase() 
    rows = [(str(x[0]), x) for x in listOfRows] 
    images = RadioField('images', validators = [Required()], choices = rows) 

입니다

@app.route('/database', methods = ['GET', 'POST']) 
def database(): 
    ''' displays the database and allows the user to select an entry ''' 
    form = DatabaseForm() 
    if form.validate_on_submit(): 

     primaryKey = form.images.data 
     primaryKey = int(primaryKey) 


     myProgram.start(primaryKey) 
     return render_template('simple.html', word = "SUCCESS") 
    else: 
     print form.errors 

    return render_template('database.html', form=form) 

답변

2

보기에서 필드 선택 항목을 설정해야합니다.

form = DatabaseForm() 
    form.images.choices = [(str(x[0]), x) for x in listOfRows] 
    if form.validate_on_submit(): 

클래스에 한 번만 설정하면 클래스가 인스턴스화 될 때만 옵션이 설정되므로 특정 프로세스의 수명 동안 변경된 사항은 반영되지 않습니다.

관련 문제