[Flask] Updating database fields from views
Anonymous Coder
anonymouscodar at gmail.com
Sat Feb 25 06:46:30 EST 2017
Just a clarity that the stackoverflow post has nothing to do with the
question. That problem I got solved. I just gave the reference to show you
how my models are defined.
Thanks
On Sat, Feb 25, 2017 at 10:26 AM, Anonymous Coder <anonymouscodar at gmail.com>
wrote:
> I am having trouble understanding how to manipulate database in Flask from
> views. Rest of topics I was able to cover pretty quickly in Flask. I am a
> new user so help is much appreciated.
>
> Following is the link for details guys from one of my post at
> stackoverflow. Thank a lot for help guys.
>
> http://stackoverflow.com/questions/42451870/flask-
> error-typeerror-incompatible-collection-type-str-is-not-
> list-like/42452448?noredirect=1#comment72048738_42452448
>
>
>
> On Sat, Feb 25, 2017 at 8:43 AM, Gergely Polonkai <gergely at polonkai.eu>
> wrote:
>
>> Where does your db variable come from?
>>
>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder <anonymouscodar at gmail.com>
>> wrote:
>>
>>> I am having trouble with updating database tables from flask view.
>>> Following is the view:
>>>
>>> @app.route('/yearlychargedrec', methods=['GET', 'POST'])
>>> def yearly_charged_rec():
>>>
>>> if not user_authorized():
>>> return redirect('/')
>>> # customer
>>> if request.method == 'POST':
>>> stripe_token = request.form['stripeToken']
>>> email = request.form['stripeEmail']
>>>
>>> customer = stripe.Customer.create(
>>> email=email,
>>> source=request.form['stripeToken']
>>> )
>>> try:
>>> subscription = stripe.Subscription.create(
>>> customer=customer.id,
>>> plan="yearlyrec",
>>> )
>>>
>>> package = Package(
>>>
>>> is_active=True,
>>> planname = 'yearlyrec',
>>>
>>> )
>>> db.session.add(package)
>>> db.session.commit()
>>>
>>> except stripe.error.CardError as e:
>>> # The card has been declined
>>> body = e.json_body
>>> err = body['error']
>>>
>>> return render_template('/profile/charge/monthlycharge.html')
>>>
>>> Error I get is:
>>>
>>> AttributeError: 'str' object has no attribute 'session'
>>>
>>> Please advise.
>>> _______________________________________________
>>> Flask mailing list
>>> Flask at python.org
>>> https://mail.python.org/mailman/listinfo/flask
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170225/ea926f15/attachment-0001.html>
More information about the Flask
mailing list