Update request

This commit is contained in:
Andros Fenollosa 2018-02-01 22:40:22 +01:00
parent 198ba20a47
commit 479a987b75
2 changed files with 16 additions and 11 deletions

View File

@ -20,3 +20,4 @@ python-dotenv = "*"
flask-script = "*" flask-script = "*"
flask-migrate = "*" flask-migrate = "*"
faker = "*" faker = "*"
flask-restplus-patched = "*"

26
app.py
View File

@ -1,26 +1,26 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Librarys # Librarys
# =========================
import os import os
from flask import Flask, jsonify from flask import Flask, jsonify, request
from flask_restplus import Resource, Api from flask_restplus import Resource, Api
from dotenv import load_dotenv, find_dotenv from dotenv import load_dotenv, find_dotenv
from models import db, User, News, Comment from models import db, User, News, Comment
# Extensions initialization
# =========================
load_dotenv(find_dotenv()) load_dotenv(find_dotenv())
app = Flask(__name__) app = Flask(__name__)
api = Api(app)
# Config Flask
# Configurations
# =========================
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY') app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY')
# Config Database
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URI') app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URI')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app) db.init_app(app)
# Config API
api = Api(app)
PRE_URL = '/api/v1/' PRE_URL = '/api/v1/'
@ -50,10 +50,10 @@ class NewsList(Resource):
def get(self): def get(self):
my_news = News.query.all() my_news = News.query.all()
return jsonify([i.serialize for i in my_news]) return serializeQuery(my_news)
def post(self): def post(self):
return {'hello': 'world'} return request.form
@api.route(PRE_URL + 'news/<int:id>') @api.route(PRE_URL + 'news/<int:id>')
@ -73,6 +73,10 @@ class Comments(Resource):
return {'hello': 'world'} return {'hello': 'world'}
def serializeQuery(query):
return jsonify([i.serialize for i in query])
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=os.environ.get('DEBUG') == 'True' if True else False) app.run(debug=os.environ.get('DEBUG') == 'True' if True else False)