[Flask] Flask Digest, Vol 3, Issue 22

David Nieder davidnieder at gmx.de
Tue Sep 22 13:05:54 CEST 2015


On 22.09.2015 03:29, Kyle Lawlor wrote:
> Hi, all.
>
> Thank you very much for the responses.
>
> @Jeff, I am actually planning on making use of the Stripe API and service.
> Currently I am just trying to build the shopping cart on the client side. I
> am taking it one step at a time.
>
> @Jonathan, Could you take a look at my code to see if I am using the
> session object correctly? I am puzzled with the current behaviour I am
> seeing. I made changes to my code, I am now attempting to store the items
> requested and compute the total price via the *session* object. Here is a
> link to the code:
> https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40
>

Well, every time a request is made to '/order' you override the content
of 'requested_item_record' with an empty list (line 40) and 'total_cost'
with a zero (line 41). You should check first if there is already
something in the session. e.g.

if not 'requested_item_record' in session:
     session['requested_item_record'] = []

I cloned you project and simply commented out those two lines.
It seems to work.

Another tip for your repository: add a .gitignore to the root folder
with sth like:
*.py~
*.pyc
venv/

You probably don't need/want those files tracked with git.


David


More information about the Flask mailing list