2016-12-16 2 views
0

병 및 몽고 데이터베이스를 사용하여 일반적인 REST API를 사용하려고합니다.mongo db가 포함 된 병 앱

내가 주소 127.0.0.1:8010/의 웹 페이지에서 점점 오전 오류가

Error: 404 Not Found

Sorry, the requested URL http ://127.0.0.1:8010/ caused an error:

Not found: '/'

명령 줄에서

, 나는이 무엇입니까입니다 : 여기

$ python myrestapi.py 

Bottle v0.12.10 server starting up (using WSGIRefServer())... 
Listening on "http://127.0.0.1:8010/" 
Hit Ctrl-C to quit. 
127.0.0.1 - - [17/Dec/2016 01:54:46] GET/HTTP/1.1 404 720 

내 코드입니다 문서/myrestapi.py :

import json 
import bottle 

from bottle import route, run, request, abort 
from pymongo import Connection 

connection = Connection('localhost', 27017) 
db = connection.mydatabase 
app = bottle.Bottle() 

@app.route('/documents', method='PUT') 
def put_document(): 
    data = request.body.readline() 

    if not data: 
    abort(400, 'No data received') 
    entity = json.loads(data) 

    if not entity.has_key('_id'): 
    abort(400, 'No _id specified') 

try: 
    db['documents'].save(entity) 

    except ValidationError as ve: 

    abort(400, str(ve)) 

@app.route('/documents/:id', method='GET') 
def get_document(id): 
entity = db['documents'].find_one({'_id':id}) 
if not entity: 
    abort(404, 'No document with id %s' % id) 
return entity 

bottle.run(host='localhost', port=8010) 
+0

I을 참조하십시오 @app.route('/documents', method='PUT')@app.route('/documents/:id', method='GET')

이 있기 때문에이 경우

당신은, 당신은 응답을 얻을 것이다 /documents 또는 /documents/1을 시도하는 경우 수직 간격을 고정했지만, 파이썬 코드의 들여 쓰기를 수정하십시오 –

+0

또한, 당신은 n o 라우트가'/'에 설정되어 있으므로'/ documents/1' 또는 어떤 ID로 시도 했습니까? –

답변

관련 문제