python - KeyError: Django Losing Session Data Between CBV Redirects -


when redirect view after adding data, stripe customer data, dict added session, lose all of information in session @ redirected view. thus, encounter keyerror when try pop these items.

interestingly, not happen when put other types of information in payment_data dict, list instead of customer object.

i'm not sure what's best way fix problem, given have designed, it's important me customer information confirm view can

  1. list item
  2. display customer information user confirmation (censoring sensitive information
  3. charge card

this code:

   class paymentscreateview(formview):        def form_valid(self, form):         customer = stripe.customer.create(description="""             non-registered user applying features""")         customer.save()          payment_data = {             'customer': customer         }          self.request.session['payment_data'] = payment_data         self.request.session.modified = true          import ipdb;ipdb.set_trace();          return httpresponseredirect(reverse('payments_confirm'))  class paymentsconfirmview(templateview):     template_name = 'payments/confirm.html'      def get_context_data(self, **kwargs):         context = super(paymentsconfirmview, self).get_context_data(**kwargs)          context['payment_data'] = self.request.session.pop('payment_data')         context['feature_data'] = self.request.session.pop('feature_data')          return context 

i'm still debugging , next step confirm whether issue trying store customer object rather dictionary or list object maybe on can confirm or supply right answer.

from python docs:

list.pop([i])

remove item @ given position in list, , return it. if no index specified, a.pop() removes , returns last item in list.

like rohan says, use get():

context['payment_data'] = self.request.session.get('payment_data', false) context['feature_data'] = self.request.session.get('feature_data', false) 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -