Data in data-structure

#this the diary model, has title, id, date_created and content.

diary model

import datetime

class diaryContent(object):
# holding the content in diary
def init(self):enter code here
self.content_items = # new content holder

def create_content(self, title, content):
    if content and title:
        now =
        date_created = now.strftime("%Y-%m-%d %H:%M")

        content_id = 1
        for con in self.content_items:
            content_id += 1
            if con[id] == content_id:
                content_id += 1

        content_save = dict()
        content_save['title'] = title
        content_save['content'] = content
        content_save['id'] = content_id
        content_save['date'] = str(date_created)
        self.content_items.append(content_save)  # appending the created content in  the self.contentitems list

        return 1
    return 0

# all available content
def all_content(self):
    return self.content_items

#the looks like this
where Am I messing up while creating a “post” request
from flask import Flask, request

from models import diaryContent # import the item

app = Flask(name)

@app.route(‘/api/V1/diary’, methods=[‘GET’])
def diary_content():
cont = diaryContent()
items = cont.all_content()

if not items:
    response = 'no items'
    return response`enter code here`
response = {"status": "success", "items": items}
return response

@app.route(‘/api/V1/diary/’, methods=[‘POST’])
def add_content():

cont = diaryContent()
tit = str('title', '')).strip()
conte = str('content', ''))
cont.create_content(tit, conte)

response = {"title": str(tit), "content": str(conte)}
return response

if name == ‘main’:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.