2016-08-11 3 views
0

여기 내 web.py 코드가 있습니다. 내 웹 서버를 사용하여 테이블을 업데이트하고 싶습니다.web.py에서 POST 메서드를 사용하여 postgreSQL 데이터베이스의 테이블을 업데이트하는 방법?

import web 


urls = ('/', 'Index') 

render = web.template.render('templates/') 

app = web.application(urls, globals()) 

web.config.debug = True 

db = web.database(dbn='postgres', db='my_db', user='postgres', pw='******', host='localhost') 

class Index: 

    def GET(self): 
     drivers = db.select("drivers") 
     return render.index(drivers) 

    def POST(self, name): 
     return "post" 

if __name__ == '__main__':app.run() 

바로 지금 테이블에있는 내용을 가져 와서 브라우저에서 인쇄합니다. 하지만 while 루프가 post 메서드를 사용하여 실행될 때 테이블에 숫자 값을 추가하는 논리를 구현하려고합니다. 어떻게해야합니까? 다음과 같이이 포스트 그레스 삽입을 할 수

답변

0

,

def POST(self): 
    sequence_id = db.insert('test1', col1=5, col2=3) # insert(tablename, seqname=None, _test=False, **values) 

은 자세한 내용은 this를 참조하십시오. 당신이 방법을 POST로 데이터를 전송하는 방법에 따라

당신은 사용할 수 있습니다,

data = json.loads(web.data()) # convert to dictionary if needed using json.loads 

또는

data = web.input().number # number is the key which holds the data 

.

예 : web.input().number

뿐만 아니라 this를 참조하십시오 사용 content-type = application/json합니다.

관련 문제