Answer the question
In order to leave comments, you need to log in
How can a cart be implemented using sessions in Flask?
Good afternoon. I started to learn python and flask, but some difficulties arose.
My idea is this - when you click on the "Add to Cart" button, the parameters of the product are transferred to the handler, they are written to the session, and all the products that are in the session are displayed on the basket page.
In php I would do it something like this:
$_SESSION["cart"][] = array("product_name" => "$_POST['product_name']");
if request.method == 'POST':
session['product_name'] = request.form['product_name']
session['product_image'] = request.form['product_image']
session['product_description'] = request.form['product_description']
return render_template('cart.html', session=session)
Answer the question
In order to leave comments, you need to log in
return render_template('cart.html', session=session)
this is not your session, but a variable in the template
flask-russian-docs.readthedocs.io/ru/latest/quicks...
https://habr.com/post/346306/
And another question, in php you can safely see what is in the session by calling print_r($_SESSION), is there something similar in python?
dir(obj), vars(obj)
https://docs.python.org/3/library/pdb.html
import pdb; pdb.set_trace()
If you don’t want to have problems with refilling, take canon, for example, www.dns-shop.ru/catalog/i160075/printer-canon-i-se...
Their chip does not block the printer, sometimes it swears that the toner is out of toner, but it prints further
Recently, Ricoh printers were advertised on Habré as those that can be refilled without chips, and without loss of warranty by refilling with non-original cartridges.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question