# -*- encoding: utf-8 -*- """ Python Aplication Template Licence: GPLv3 """ from flask import request from flask_restless import APIManager from flask_restful import Resource,Api from app import app,db from models import Post,Paragraph,Comment # Create the Flask-Restless API manager. manager = APIManager(app, flask_sqlalchemy_db=db) # Create API endpoints, which will be available at /api/ by # default. Allowed HTTP methods can be specified as well. manager.create_api(Post, methods=['GET']) manager.create_api(Paragraph, methods=['GET']) manager.create_api(Comment, methods=['GET','POST']) restapi = Api(app) @app.route('/') def index(): return app.send_static_file('index.html') class CreatePost(Resource): def post(self): try: post_data = json.parse(request.data) title = post_data['title'] content = post_data['content'] p = Post(title) pgs = content.split('\n') db.session.add(p) db.session.add(p) return {'post_id':'title'} except Exception as e: return {'error':'invalid_post'} restapi.add_resource(CreatePost,'/api/create_post') # @app.route('/api/create_post',methods=['POST']) # def create_post(): # title = request.form.get('title',None); # content = request.form.get('content',None) # print(title,content) # return 'ok' # # @app.route('/api/addpost',methods=['POST']) # def addpost(): # return 'Post Added' # # @app.route('/api/listposts') # def listposts(): # return 'Post Added' # ====================