Merge branch 'feature/DbReader' into develop
commit
13e4d17a7c
@ -1,2 +1,2 @@
|
|||||||
.venv/*
|
.venv/*
|
||||||
|
params.yaml
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
"helper functions"
|
||||||
|
|
||||||
|
from flask import abort
|
||||||
|
|
||||||
|
def find_one_or_404(collection, **kwargs):
|
||||||
|
"""Find a single document or raise a 404.
|
||||||
|
|
||||||
|
This is like :meth:`~pymongo.collection.Collection.find_one`, but
|
||||||
|
rather than returning ``None``, cause a 404 Not Found HTTP status
|
||||||
|
on the request.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
usercollection = mydb['usercollection']
|
||||||
|
|
||||||
|
@app.route("/user/<username>")
|
||||||
|
def user_profile(username):
|
||||||
|
userfound = find_one_or_404(usercollection, {"_id": username})
|
||||||
|
return render_template("user.html",
|
||||||
|
user=userfound)
|
||||||
|
"""
|
||||||
|
found = collection.find_one(**kwargs)
|
||||||
|
if found is None:
|
||||||
|
abort(404)
|
||||||
|
return found
|
||||||
|
|
||||||
Loading…
Reference in New Issue