2
This commit is contained in:
@@ -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
19
app/db.py
Normal 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
17
app/routes.py
Normal 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"
|
||||
Reference in New Issue
Block a user