diff --git a/README.md b/README.md index bc6e2a4..5ad4a0a 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,20 @@ DB: pythoncms Table: posts Format: - +``` { "_id": "0123456789", "name": "Title", "text": "Hello, this is post" } +``` +Index page: + +``` +{ + "_id": "0123456789", + "name": "/", + "text": "Hello, this is index page" +} + +``` \ No newline at end of file diff --git a/main.py b/main.py index 159ac8a..5db80eb 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -from bottle import route, run, template, debug, request +from bottle import abort, route, run, template, debug, request import pymongo mongoclient = pymongo.MongoClient('localhost', 27017) @@ -12,7 +12,10 @@ def post(name): ''' Get post ''' - return posts.find_one({'name':name})['text'] + try: + return posts.find_one({'name':name})['text'] + except TypeError: + return abort(404, 'No such page') @route('/post/', method='POST') @@ -52,7 +55,10 @@ def all_posts(): @route('/') def index(): - return "Hello" + try: + return posts.find_one({'name':'/'})['text'] + except TypeError: + return abort(404, 'No such page') if __name__ == '__main__':