-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
37 lines (26 loc) · 943 Bytes
/
app.py
File metadata and controls
37 lines (26 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, abort, jsonify, request, url_for
from flask_restful import Api
from models import Product, User, db
from resources import ProductResource, UserResource
from schema import ma
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
db.init_app(app)
ma.init_app(app)
api = Api(app)
api.add_resource(UserResource, '/api/users')
api.add_resource(ProductResource, '/products','/product/<int:product_id>')
with app.app_context():
try:
db.drop_all()
db.create_all()
test = Product(name="Test",description="desc",price="20")
db.session.add(test)
db.session.commit()
mon_test = db.session.query(Product).filter(Product.name == "Test").first()
print(f"{mon_test.id} {mon_test.name}: {mon_test.description}")
except(e):
print("erreur")
pass
if __name__ == "__main__":
app.run(ssl_context=('cert.pem', 'key.pem'))