This commit is contained in:
2023-09-27 09:33:00 +02:00
parent 2de7f2fea1
commit 00d7456f89
6 changed files with 60 additions and 2 deletions

View File

@@ -11,5 +11,5 @@ if path.exists((cfg_pth := path.join(config_path, "../config.cfg"))):
config.read(cfg_pth)
settings = {
"mongodb_url": config.get("DB","MONGODB_URL")
"mongodb_uri": config.get("DB","MONGODB_URI")
}

19
app/db.py Normal file
View File

@@ -0,0 +1,19 @@
from flask import current_app, g
from werkzeug.local import LocalProxy
from flask_pymongo import PyMongo
def get_db():
"""
Configuration method to return db instance
"""
db = getattr(g, "_database", None)
if db is None:
db = g._database = PyMongo(current_app).db
return db
# Use LocalProxy to read the global db instance with just `db`
db = LocalProxy(get_db)

17
app/routes.py Normal file
View File

@@ -0,0 +1,17 @@
from flask import current_app as app
from flask import request
from .db import db
@app.route("/detail", methods=["GET"])
def detail():
if "ico" not in request.args:
return "missing ico"
else:
ico = request.args["ico"]
return f"ICO je {ico}"
@app.route("/list", methods=["GET"])
def list_data():
return "list"

View File

@@ -1,2 +1,2 @@
[DB]
MONGODB_URL = "mongodb://localhost:27017"
MONGODB_URI = "mongodb://localhost:27017/softone"

View File

@@ -0,0 +1,20 @@
from flask import Flask
from app.config import settings
def create_app():
flaskapp = Flask(__name__)
with flaskapp.app_context():
from app import routes
return flaskapp
if __name__ == "__main__":
app = create_app()
app.config["Debug"] = True
app.config["MONGO_URI"] = settings["mongodb_uri"]
app.run()

View File

@@ -0,0 +1,2 @@
Flask~=2.3.3
Flask-PyMongo~=2.3.0