from flask import jsonify
# Begin AJAX requests
@cart.route("/api/total")
def total():
count = 0
if "cart" in session:
cart = session.get("cart")
l = [int(i) for i in redis.hvals(getCartKey(cart))]
count = sum(l)
logger.debug('cart %s : %d', cart, count)
data = calculateItems()
data.pop("products")
return jsonify(dict(count=count, **data))
"""Creates a :class:`~flask.Response` with the JSON representation of
the given arguments with an `application/json` mimetype. The arguments
to this function are the same as to the :class:`dict` constructor.
Example usage::
from flask import jsonify
@app.route('/_get_current_user')
def get_current_user():
return jsonify(username=g.user.username,
email=g.user.email,
id=g.user.id)
This will send a JSON response like this to the browser::
{
"username": "admin",
"email": "admin@localhost",
"id": 42
}
For security reasons only objects are supported toplevel. For more
information about this, have a look at :ref:`json-security`.
This function's response will be pretty printed if it was not requested
with ``X-Requested-With: XMLHttpRequest`` to simplify debugging unless
the ``JSONIFY_PRETTYPRINT_REGULAR`` config parameter is set to false.
.. versionadded:: 0.2
"""
import platform
if platform.system() == 'Linux':
MYAPPPATH = "/var/www/FlaskApp/FlaskApp"
else:
MYAPPPATH = "C:/FlaskApp/FlaskApp"
import platform
if platform.system() == 'Linux':
app.config["MYAPPPATH"] = "/var/www/FlaskApp/FlaskApp"
else:
app.config["MYAPPPATH"] = "C:/FlaskApp/FlaskApp"
file = open(app.config["MYAPPPATH"]+'/myfile', 'w')