From cca16d69b53f91e0a347089b96851fc30b34a856 Mon Sep 17 00:00:00 2001 From: Lulzette Date: Tue, 7 Sep 2021 07:14:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D1=83=20404=20?= =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20+=D0=BF=D0=BE=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20index=20page.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 ++++++++++++- main.py | 12 +++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) 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__':