2015-01-25 4 views
0

이 내가이 edit_item 방법은 작업 할 수 있도록 노력하고병 프레임 워크 PUT 요청

import sqlite3 
import json 
from bottle import route, run, request 

def dict_factory(cursor, row): 
     d = {} 
     for idx, col in enumerate(cursor.description): 
       d[col[0]] = row[idx] 
     return d 

def db_connect(): 
     conn = sqlite3.connect('inventory.db') 
     conn.row_factory = dict_factory 
     return conn, conn.cursor() 

@route('/inventory', method='GET') 
def get_inventory(): 
    conn,c=db_connect() 
    c.execute("SELECT id, name, category, location, date, amount FROM inventory") 
    result = c.fetchall() 
    json_result=json.dumps(result) 
    return json_result 

@route('/inventory/get/:id', method='GET') 
def get_item(id): 
    conn,c=db_connect() 
    c.execute("SELECT id, name, category, location, date, amount FROM inventory WHERE id=?",(id,)) 
    result=c.fetchall() 
    json_result=json.dumps(result) 
    return json_result 

@route('/inventory/new', method='POST') 
def add_item(): 
    name = request.POST.get('name') 
    category = request.POST.get('category') 
    location = request.POST.get('location') 
    date = request.POST.get('date') 
    amount = request.POST.get('amount') 
    conn,c=db_connect() 
    c.execute("INSERT INTO inventory (name, category, location, date, amount) VALUES (?,?,?,?,?)", (name,category,location,date,amount)) 
    new_id = c.lastrowid 
    conn.commit() 
    c.close() 
    return '<p>The entry with id %d has been added to the database</p>' %new_id 

@route('/inventory/delete/:id', method='DELETE') 
def delete_item(id): 
    conn,c=db_connect() 
    c.execute("DELETE FROM inventory WHERE id =?", (id,)) 
    conn.commit() 
    c.close() 
    return 'The entry with id %s has been deleted from the database' %id 

@route('/inventory/edit/:id', method='PUT') 
def edit_item(id): 
    name = request.PUT.get('name') 
    category = request.PUT.get('category') 
    amount = request.PUT.get('location') 
    location = request.PUT.get('date') 
    date = request.PUT.get('amount') 
    conn,c=db_connect() 
    c.execute("UPDATE Inventory SET name=?, category=?, location=?, date=?, amount=? WHERE id=?", (name, category, location, date, amount,id)) 
    conn.commit() 
    c.close(); 
    return '<p>The entry with id %s has been edited in the database</p>' %id 


run(reloader=True) 

내 병 코드입니다. 나는 curl -X PUT -d "name=aa&category=bb&amount=23&location=xx&date=21-10-2014" http://localhost:8080/inventory/edit/2

내가 대신이의

raise AttributeError('Atrribute %r is not defined.' % name) AttributeError: Attribute 'PUT' not defined' What should i do ?

답변

0

을 말한다 서버 오류,

name = request.PUT.get('name') 

사용이 얻을 컬로를 호출 할 때 :

name = request.params.get('name')