Update database
This commit is contained in:
parent
766c0d868f
commit
198ba20a47
11
app.py
11
app.py
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Librarys
|
# Librarys
|
||||||
import os
|
import os
|
||||||
from flask import Flask
|
from flask import Flask, jsonify
|
||||||
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
|
||||||
@ -14,6 +14,11 @@ app = Flask(__name__)
|
|||||||
# Config Flask
|
# Config Flask
|
||||||
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_TRACK_MODIFICATIONS'] = False
|
||||||
|
db.init_app(app)
|
||||||
|
|
||||||
# Config API
|
# Config API
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
PRE_URL = '/api/v1/'
|
PRE_URL = '/api/v1/'
|
||||||
@ -41,11 +46,11 @@ class Logout(Resource):
|
|||||||
|
|
||||||
|
|
||||||
@api.route(PRE_URL + 'news')
|
@api.route(PRE_URL + 'news')
|
||||||
class News_all(Resource):
|
class NewsList(Resource):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
my_news = News.query.all()
|
my_news = News.query.all()
|
||||||
return ([i.serialize for i in my_news])
|
return jsonify([i.serialize for i in my_news])
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
return {'hello': 'world'}
|
return {'hello': 'world'}
|
||||||
|
Loading…
Reference in New Issue
Block a user