From amitjalota124 at gmail.com Tue Feb 14 03:55:13 2017 From: amitjalota124 at gmail.com (Amit Jalota) Date: Tue, 14 Feb 2017 14:25:13 +0530 Subject: [Flask] New to Flask Message-ID: Hi , I am very new to flask . i have to write some REST API's and my backend code is python based. I downloaded flask toolkit from git clone http://github.com/pallets/flask.git i am not sure whether this is the toolkit. can you please confirm. do i need to integrate this toolkit with out stack. Can you please help to to move further. Thanks, Amit -------------- next part -------------- An HTML attachment was scrubbed... URL: From unai at sysbible.org Tue Feb 14 04:09:37 2017 From: unai at sysbible.org (Unai Rodriguez) Date: Tue, 14 Feb 2017 17:09:37 +0800 Subject: [Flask] New to Flask In-Reply-To: References: Message-ID: <1487063377.2380073.880349240.1B3A2A84@webmail.messagingengine.com> Documentation for the latest stable version: http://flask.pocoo.org/docs/0.12/installation/ This is what you need I guess? -- unai On Tue, Feb 14, 2017, at 04:55 PM, Amit Jalota wrote: > Hi , > I am very new to flask . > i have to write some REST API's and my backend code is python based. > > I downloaded flask toolkit from git clone > http://github.com/pallets/flask.git > > i am not sure whether this is the toolkit. can you please confirm. > > do i need to integrate this toolkit with out stack. > > Can you please help to to move further. > > Thanks, > Amit > > > _________________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From paradox2005 at gmail.com Tue Feb 14 04:12:57 2017 From: paradox2005 at gmail.com (Adil Hasan) Date: Tue, 14 Feb 2017 09:12:57 +0000 Subject: [Flask] New to Flask In-Reply-To: References: Message-ID: <20170214091256.GC24721@satsuma> Hello Amit, Miguel Grinberg has written some useful tutorials on REST with Flask: https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask there are links to two other tutorials. I found them very useful. Hopefully, they will be useful to you too. adil On Tue, Feb 14, 2017 at 02:25:13PM +0530, Amit Jalota wrote: > Hi , > I am very new to flask . > i have to write some REST API's and my backend code is python based. > > I downloaded flask toolkit from git clone > http://github.com/pallets/flask.git > > i am not sure whether this is the toolkit. can you please confirm. > > do i need to integrate this toolkit with out stack. > > Can you please help to to move further. > > Thanks, > Amit > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask From thomas.david.vaughan at gmail.com Tue Feb 14 07:56:27 2017 From: thomas.david.vaughan at gmail.com (Tom Vaughan) Date: Tue, 14 Feb 2017 09:56:27 -0300 Subject: [Flask] New to Flask In-Reply-To: References: Message-ID: This https://gitlab.com/tvaughan/docker-flask-starterkit may be helpful. On Tue, Feb 14, 2017 at 5:55 AM, Amit Jalota wrote: > Hi , > I am very new to flask . > i have to write some REST API's and my backend code is python based. > > I downloaded flask toolkit from git clone > http://github.com/pallets/flask.git > > i am not sure whether this is the toolkit. can you please confirm. > > do i need to integrate this toolkit with out stack. > > Can you please help to to move further. > > Thanks, > Amit > > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > From dnikiforov at linkedin.com Tue Feb 21 14:28:24 2017 From: dnikiforov at linkedin.com (Dmitry Nikiforov) Date: Tue, 21 Feb 2017 11:28:24 -0800 Subject: [Flask] Prevent saving of temp file during upload Message-ID: Hello All! I've been looking for a way to prevent Flask/Request/FileStorage from saving uploaded files on the disk and instead digest them with my own code. Most (all?) results from Google simply tell to just do file.read(), but that still results in a file saved in a temp directory and read from the disk. I'm trying to avoid that, because the uploaded file needs to actually be passed on to an underlying storage (LI Ambry), and can be hundreds of gigabytes in size. It's not viable to store the file first and then pass it on to the final storage service :( I see that both Request and FileStorage classes can accept a "shallow" parameter, but there's virtually no information on what it actually does, or how to use it :( Any help or suggestions would be greatly appreciated! -- D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dnikiforov at linkedin.com Tue Feb 21 14:32:00 2017 From: dnikiforov at linkedin.com (Dmitry Nikiforov) Date: Tue, 21 Feb 2017 11:32:00 -0800 Subject: [Flask] Prevent saving of temp file during upload In-Reply-To: References: Message-ID: I'm guessing the goal is to get access to wsgi directly and prevent Request and/or FileStorage from eating up the uploaded data... P.S. Python newbie here, so apologies for possibly stupid questions :) On Tue, Feb 21, 2017 at 11:28 AM, Dmitry Nikiforov wrote: > Hello All! > > I've been looking for a way to prevent Flask/Request/FileStorage from > saving uploaded files on the disk and instead digest them with my own code. > > Most (all?) results from Google simply tell to just do file.read(), but > that still results in a file saved in a temp directory and read from the > disk. I'm trying to avoid that, because the uploaded file needs to actually > be passed on to an underlying storage (LI Ambry), and can be hundreds of > gigabytes in size. It's not viable to store the file first and then pass it > on to the final storage service :( > > I see that both Request and FileStorage classes can accept a "shallow" > parameter, but there's virtually no information on what it actually does, > or how to use it :( > > Any help or suggestions would be greatly appreciated! > > -- > D. > -- D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From amitjalota124 at gmail.com Wed Feb 22 04:07:30 2017 From: amitjalota124 at gmail.com (Amit Jalota) Date: Wed, 22 Feb 2017 14:37:30 +0530 Subject: [Flask] Flask with Json Format Message-ID: Hi All, Is there is any good tutorial/handson which will return the data in Json format with examples like handlers which will fetch the real time data. I went through mentioned below tutorial https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world and currently I hardcoded the the Json data and returned to browser now I need to return some real time data from microblog/virtualenv-15.1.0/app/views.py instead of hardcoded. from flask import Flask,jsonify,json from app import app @app.route("/getEmployeeList") def getEmployeeList(): try: # Initialize a employee list employeeList = [] # create a instances for filling up employee list for i in range(0,2): empDict = { 'firstName': 'Roy', 'lastName': 'Augustine'} employeeList.append(empDict) # convert to json data jsonStr = json.dumps(employeeList) except Exception ,e: print str(e) return jsonify(Employees=jsonStr) and can you please help me for interface as well to lower backed layer. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From coreybrett at gmail.com Wed Feb 22 07:53:15 2017 From: coreybrett at gmail.com (Corey Boyle) Date: Wed, 22 Feb 2017 07:53:15 -0500 Subject: [Flask] Flask with Json Format In-Reply-To: References: Message-ID: Where is your data being held? On Wed, Feb 22, 2017 at 4:07 AM, Amit Jalota wrote: > Hi All, > Is there is any good tutorial/handson which will return the data > in Json format with examples like handlers which will fetch the real time > data. > > I went through mentioned below tutorial > https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world > and currently I hardcoded the the Json data and returned to browser > now I need to return some real time data from > microblog/virtualenv-15.1.0/app/views.py > > instead of hardcoded. > > from flask import Flask,jsonify,json > from app import app > @app.route("/getEmployeeList") > def getEmployeeList(): > try: > # Initialize a employee list > employeeList = [] > # create a instances for filling up employee list > for i in range(0,2): > empDict = { > 'firstName': 'Roy', > 'lastName': 'Augustine'} > employeeList.append(empDict) > # convert to json data > jsonStr = json.dumps(employeeList) > except Exception ,e: > print str(e) > return jsonify(Employees=jsonStr) > > > > and can you please help me for interface as well to lower backed layer. > > Thanks > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > From amitjalota124 at gmail.com Wed Feb 22 21:07:49 2017 From: amitjalota124 at gmail.com (Amit Jalota) Date: Thu, 23 Feb 2017 07:37:49 +0530 Subject: [Flask] Flask with Json Format In-Reply-To: References: Message-ID: Its run time data.. On 22 February 2017 at 18:23, Corey Boyle wrote: > Where is your data being held? > > On Wed, Feb 22, 2017 at 4:07 AM, Amit Jalota > wrote: > > Hi All, > > Is there is any good tutorial/handson which will return the > data > > in Json format with examples like handlers which will fetch the real time > > data. > > > > I went through mentioned below tutorial > > https://blog.miguelgrinberg.com/post/the-flask-mega- > tutorial-part-i-hello-world > > and currently I hardcoded the the Json data and returned to browser > > now I need to return some real time data from > > microblog/virtualenv-15.1.0/app/views.py > > > > instead of hardcoded. > > > > from flask import Flask,jsonify,json > > from app import app > > @app.route("/getEmployeeList") > > def getEmployeeList(): > > try: > > # Initialize a employee list > > employeeList = [] > > # create a instances for filling up employee list > > for i in range(0,2): > > empDict = { > > 'firstName': 'Roy', > > 'lastName': 'Augustine'} > > employeeList.append(empDict) > > # convert to json data > > jsonStr = json.dumps(employeeList) > > except Exception ,e: > > print str(e) > > return jsonify(Employees=jsonStr) > > > > > > > > and can you please help me for interface as well to lower backed layer. > > > > Thanks > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anonymouscodar at gmail.com Fri Feb 24 21:27:40 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sat, 25 Feb 2017 02:27:40 +0000 Subject: [Flask] DB Updates based on events Message-ID: Hi, I've created a view for stripe payments. Now upon success I need to update my local database table. I am new to Flask so I have no clue how to do it plus there are multiple ways I've tried and couldn't make it work. It is like sub model attached to parent model with ForeignKey, What I need is to update Package field in database upon I commit to child table automatically. Following is my view and Model: View: @app.route('/yearlyrecurring') def subscriptions_yearly_recurring(): if not user_authorized(): return redirect('/') key = stripe_keys['publishable_key'] charge_all = stripe.Charge.list(limit=895) charge_dic = {} charge_list = [] for charge_data in charge_all: charge_dic['Amount'] = "$" + str(float(charge_data.amount) / 100) + " " + charge_data.currency.upper() charge_dic['Description'] = charge_data.description charge_dic['Name'] = charge_data.receipt_email charge_dic['Date'] = str(datetime.datetime.fromtimestamp(charge_data.created)) charge_list.append(charge_dic) charge_dic = {} return render_template('/profile/packages/annualrecurring.html', **locals()) @app.route('/yearlychargedrec', methods=['POST']) def yearly_charged_rec(): if not user_authorized(): return redirect('/') # customer 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", ) 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') My Model: #Parent model Student(db.Model): ...... package = relationship('Package', backref=backref('student")) ...... Packages(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) student_id = db.Column(db.Integer, ForeignKey('student_profile.id')) stripe_id = db.Column(db.String(45)) student_email = db.Column(db.String(20)) subscription_date = db.Column(db.DateTime, default=today) expiry_date = db.Column(db.DateTime, default=deadline) is_active = db.Column(db.Boolean, default=True) planname = relationship('Plan', backref=backref('package')) package_price = db.Column(db.Integer) coupon = db.Column(db.String(12)) def __init__(self, id, student_id, stripe_id, student_email, subscription_date, expiry_date, is_active, planname, package_price, coupon): self.id = id self.stripe_id = stripe_id self.student_id = student_id self.student_email = student_email self.subscription_date = subscription_date self.expiry_date = expiry_date self.is_active = is_active self.planname = planname self.package_price = package_price self.coupon = coupon -------------- next part -------------- An HTML attachment was scrubbed... URL: From anonymouscodar at gmail.com Sat Feb 25 02:35:54 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sat, 25 Feb 2017 07:35:54 +0000 Subject: [Flask] Updating database fields from views Message-ID: 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Sat Feb 25 03:43:59 2017 From: gergely at polonkai.eu (Gergely Polonkai) Date: Sat, 25 Feb 2017 08:43:59 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: Where does your db variable come from? On Sat, Feb 25, 2017, 08:36 Anonymous Coder 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: From anonymouscodar at gmail.com Sat Feb 25 05:26:32 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sat, 25 Feb 2017 10:26:32 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: 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 wrote: > Where does your db variable come from? > > On Sat, Feb 25, 2017, 08:36 Anonymous Coder > 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: From anonymouscodar at gmail.com Sat Feb 25 06:46:30 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sat, 25 Feb 2017 11:46:30 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: 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 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 > wrote: > >> Where does your db variable come from? >> >> On Sat, Feb 25, 2017, 08:36 Anonymous Coder >> 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: From gergely at polonkai.eu Sat Feb 25 06:51:54 2017 From: gergely at polonkai.eu (Gergely Polonkai) Date: Sat, 25 Feb 2017 11:51:54 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: The error message you showed us most probably references the db variable. Is db a global variable in the same file? Or is it imported from another module? Can you check its value? On Sat, Feb 25, 2017, 12:46 Anonymous Coder wrote: > 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 > wrote: > > Where does your db variable come from? > > On Sat, Feb 25, 2017, 08:36 Anonymous Coder > 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: From anonymouscodar at gmail.com Sat Feb 25 07:40:30 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sat, 25 Feb 2017 12:40:30 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: It is imported from another file. On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai wrote: > The error message you showed us most probably references the db variable. > Is db a global variable in the same file? Or is it imported from another > module? Can you check its value? > > On Sat, Feb 25, 2017, 12:46 Anonymous Coder > wrote: > >> 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 >> wrote: >> >> Where does your db variable come from? >> >> On Sat, Feb 25, 2017, 08:36 Anonymous Coder >> 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: From thomas.david.vaughan at gmail.com Sat Feb 25 08:50:01 2017 From: thomas.david.vaughan at gmail.com (Tom Vaughan) Date: Sat, 25 Feb 2017 10:50:01 -0300 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: But how exactly is it imported? Where is it assigned a value? The problem seems to be that db is not an instance of a Database object, but rather it has been assigned a string. For example: $ python3 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> db = "foobar" >>> db.session Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute 'session' On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder wrote: > It is imported from another file. > > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai > wrote: >> >> The error message you showed us most probably references the db variable. >> Is db a global variable in the same file? Or is it imported from another >> module? Can you check its value? >> >> >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder >> wrote: >>> >>> 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 >>> 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 >>>> wrote: >>>>> >>>>> Where does your db variable come from? >>>>> >>>>> >>>>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder >>>>> 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 >>>> >>>> >>> > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > From anonymouscodar at gmail.com Sat Feb 25 09:35:02 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sat, 25 Feb 2017 14:35:02 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: I think I found it. I really am sorry that I was not clearly lay down source code reflecting the issue and thanks for the patience. In __init__ file the previous developer has something like below: #File1 login_manager = LoginManager() login_manager.init_app(app) db = { 'users': { "test": ("test", "test") }, 'session': {} } app.config['DEBUG'] = True app.config['WTF_CSRF_ENABLED'] = False app.secret_key = '\x06\x94\xcf\xaf\xaeB&\xd1s\xa8ZGU\xd2J\xf3\xd6\x12(\xbd\xf5\xc3\x858' db = 'db' Then in another file he declared the database like below: #File 2 import os import oursql from flask import Flask app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+ 'root' \ + ':' + 'test123'+'@'\ + 'localhost' + '/students' db = SQLAlchemy(app) def get_connection(): return oursql.connect(host='localhost', port='3306', user='root', passwd='test123', db='students') Now when I need to create any model and need to add tables I do this in shell: from file2 import db from somemodelfile import MyNewModel db.create_all() That is how it adds tables. But still I am confuse that why it is not letting me update fields. Except above code there is no representation of data related to how db needs to be handled. All the file inside project call database from file1 but in shell I can't use create_db(). When in shell I do like below: >>>from file1 import db >>>db 'db' #This is the output On Sat, Feb 25, 2017 at 1:50 PM, Tom Vaughan wrote: > But how exactly is it imported? Where is it assigned a value? The > problem seems to be that db is not an instance of a Database object, > but rather it has been assigned a string. For example: > > $ python3 > Python 3.5.2 (default, Nov 17 2016, 17:05:23) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> db = "foobar" > >>> db.session > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'str' object has no attribute 'session' > > > > On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder > wrote: > > It is imported from another file. > > > > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai > > wrote: > >> > >> The error message you showed us most probably references the db > variable. > >> Is db a global variable in the same file? Or is it imported from another > >> module? Can you check its value? > >> > >> > >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder > >> wrote: > >>> > >>> 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 > >>> 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 > >>>> > >>>> > >>> > > > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.david.vaughan at gmail.com Sat Feb 25 09:41:53 2017 From: thomas.david.vaughan at gmail.com (Tom Vaughan) Date: Sat, 25 Feb 2017 11:41:53 -0300 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: On Sat, Feb 25, 2017 at 11:35 AM, Anonymous Coder wrote: > I think I found it. I really am sorry that I was not clearly lay down source > code reflecting the issue and thanks for the patience. In __init__ file the > previous developer has something like below: > > #File1 > login_manager = LoginManager() > login_manager.init_app(app) > > db = { > 'users': { > "test": ("test", "test") > }, > 'session': {} > } > app.config['DEBUG'] = True > app.config['WTF_CSRF_ENABLED'] = False > app.secret_key = > '\x06\x94\xcf\xaf\xaeB&\xd1s\xa8ZGU\xd2J\xf3\xd6\x12(\xbd\xf5\xc3\x858' > > db = 'db' ^^^ Delete this line completely. > > Then in another file he declared the database like below: > > #File 2 > import os > import oursql > from flask import Flask > > app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+ 'root' \ > + ':' + 'test123'+'@'\ > + 'localhost' + '/students' > db = SQLAlchemy(app) > def get_connection(): > return oursql.connect(host='localhost', port='3306', > user='root', > passwd='test123', db='students') > > Now when I need to create any model and need to add tables I do this in > shell: > > from file2 import db > from somemodelfile import MyNewModel > db.create_all() > > That is how it adds tables. But still I am confuse that why it is not > letting me update fields. > > Except above code there is no representation of data related to how db needs > to be handled. All the file inside project call database from file1 but in > shell I can't use create_db(). When in shell I do like below: > >>>>from file1 import db >>>>db > 'db' #This is the output > > > > On Sat, Feb 25, 2017 at 1:50 PM, Tom Vaughan > wrote: >> >> But how exactly is it imported? Where is it assigned a value? The >> problem seems to be that db is not an instance of a Database object, >> but rather it has been assigned a string. For example: >> >> $ python3 >> Python 3.5.2 (default, Nov 17 2016, 17:05:23) >> [GCC 5.4.0 20160609] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> >>> db = "foobar" >> >>> db.session >> Traceback (most recent call last): >> File "", line 1, in >> AttributeError: 'str' object has no attribute 'session' >> >> >> >> On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder >> wrote: >> > It is imported from another file. >> > >> > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai >> > wrote: >> >> >> >> The error message you showed us most probably references the db >> >> variable. >> >> Is db a global variable in the same file? Or is it imported from >> >> another >> >> module? Can you check its value? >> >> >> >> >> >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder >> >> wrote: >> >>> >> >>> 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 >> >>> 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 >> >>>> >> >>>> wrote: >> >>>>> >> >>>>> Where does your db variable come from? >> >>>>> >> >>>>> >> >>>>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder >> >>>>> >> >>>>> 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 >> >>>> >> >>>> >> >>> >> > >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> > > > From anonymouscodar at gmail.com Sat Feb 25 10:07:49 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sat, 25 Feb 2017 15:07:49 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: You mean I should delete following line? db='db' On Sat, Feb 25, 2017 at 2:41 PM, Tom Vaughan wrote: > On Sat, Feb 25, 2017 at 11:35 AM, Anonymous Coder > wrote: > > I think I found it. I really am sorry that I was not clearly lay down > source > > code reflecting the issue and thanks for the patience. In __init__ file > the > > previous developer has something like below: > > > > #File1 > > login_manager = LoginManager() > > login_manager.init_app(app) > > > > db = { > > 'users': { > > "test": ("test", "test") > > }, > > 'session': {} > > } > > app.config['DEBUG'] = True > > app.config['WTF_CSRF_ENABLED'] = False > > app.secret_key = > > '\x06\x94\xcf\xaf\xaeB&\xd1s\xa8ZGU\xd2J\xf3\xd6\x12(\xbd\xf5\xc3\x858' > > > > db = 'db' > > ^^^ Delete this line completely. > > > > > > Then in another file he declared the database like below: > > > > #File 2 > > import os > > import oursql > > from flask import Flask > > > > app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+ 'root' \ > > + ':' + 'test123'+'@'\ > > + 'localhost' + '/students' > > db = SQLAlchemy(app) > > def get_connection(): > > return oursql.connect(host='localhost', port='3306', > > user='root', > > passwd='test123', db='students') > > > > Now when I need to create any model and need to add tables I do this in > > shell: > > > > from file2 import db > > from somemodelfile import MyNewModel > > db.create_all() > > > > That is how it adds tables. But still I am confuse that why it is not > > letting me update fields. > > > > Except above code there is no representation of data related to how db > needs > > to be handled. All the file inside project call database from file1 but > in > > shell I can't use create_db(). When in shell I do like below: > > > >>>>from file1 import db > >>>>db > > 'db' #This is the output > > > > > > > > On Sat, Feb 25, 2017 at 1:50 PM, Tom Vaughan > > wrote: > >> > >> But how exactly is it imported? Where is it assigned a value? The > >> problem seems to be that db is not an instance of a Database object, > >> but rather it has been assigned a string. For example: > >> > >> $ python3 > >> Python 3.5.2 (default, Nov 17 2016, 17:05:23) > >> [GCC 5.4.0 20160609] on linux > >> Type "help", "copyright", "credits" or "license" for more information. > >> >>> db = "foobar" > >> >>> db.session > >> Traceback (most recent call last): > >> File "", line 1, in > >> AttributeError: 'str' object has no attribute 'session' > >> > >> > >> > >> On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder > >> wrote: > >> > It is imported from another file. > >> > > >> > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai < > gergely at polonkai.eu> > >> > wrote: > >> >> > >> >> The error message you showed us most probably references the db > >> >> variable. > >> >> Is db a global variable in the same file? Or is it imported from > >> >> another > >> >> module? Can you check its value? > >> >> > >> >> > >> >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder < > anonymouscodar at gmail.com> > >> >> wrote: > >> >>> > >> >>> 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 > >> >>> 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 > >> >>>> > >> >>>> wrote: > >> >>>>> > >> >>>>> Where does your db variable come from? > >> >>>>> > >> >>>>> > >> >>>>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder > >> >>>>> > >> >>>>> 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 > >> >>>> > >> >>>> > >> >>> > >> > > >> > > >> > _______________________________________________ > >> > Flask mailing list > >> > Flask at python.org > >> > https://mail.python.org/mailman/listinfo/flask > >> > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.david.vaughan at gmail.com Sat Feb 25 10:09:48 2017 From: thomas.david.vaughan at gmail.com (Tom Vaughan) Date: Sat, 25 Feb 2017 12:09:48 -0300 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: On Sat, Feb 25, 2017 at 12:07 PM, Anonymous Coder wrote: > You mean I should delete following line? > > db='db' Yes. > > On Sat, Feb 25, 2017 at 2:41 PM, Tom Vaughan > wrote: >> >> On Sat, Feb 25, 2017 at 11:35 AM, Anonymous Coder >> wrote: >> > I think I found it. I really am sorry that I was not clearly lay down >> > source >> > code reflecting the issue and thanks for the patience. In __init__ file >> > the >> > previous developer has something like below: >> > >> > #File1 >> > login_manager = LoginManager() >> > login_manager.init_app(app) >> > >> > db = { >> > 'users': { >> > "test": ("test", "test") >> > }, >> > 'session': {} >> > } >> > app.config['DEBUG'] = True >> > app.config['WTF_CSRF_ENABLED'] = False >> > app.secret_key = >> > '\x06\x94\xcf\xaf\xaeB&\xd1s\xa8ZGU\xd2J\xf3\xd6\x12(\xbd\xf5\xc3\x858' >> > >> > db = 'db' >> >> ^^^ Delete this line completely. >> >> >> > >> > Then in another file he declared the database like below: >> > >> > #File 2 >> > import os >> > import oursql >> > from flask import Flask >> > >> > app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+ 'root' \ >> > + ':' + 'test123'+'@'\ >> > + 'localhost' + '/students' >> > db = SQLAlchemy(app) >> > def get_connection(): >> > return oursql.connect(host='localhost', port='3306', >> > user='root', >> > passwd='test123', db='students') >> > >> > Now when I need to create any model and need to add tables I do this in >> > shell: >> > >> > from file2 import db >> > from somemodelfile import MyNewModel >> > db.create_all() >> > >> > That is how it adds tables. But still I am confuse that why it is not >> > letting me update fields. >> > >> > Except above code there is no representation of data related to how db >> > needs >> > to be handled. All the file inside project call database from file1 but >> > in >> > shell I can't use create_db(). When in shell I do like below: >> > >> >>>>from file1 import db >> >>>>db >> > 'db' #This is the output >> > >> > >> > >> > On Sat, Feb 25, 2017 at 1:50 PM, Tom Vaughan >> > wrote: >> >> >> >> But how exactly is it imported? Where is it assigned a value? The >> >> problem seems to be that db is not an instance of a Database object, >> >> but rather it has been assigned a string. For example: >> >> >> >> $ python3 >> >> Python 3.5.2 (default, Nov 17 2016, 17:05:23) >> >> [GCC 5.4.0 20160609] on linux >> >> Type "help", "copyright", "credits" or "license" for more information. >> >> >>> db = "foobar" >> >> >>> db.session >> >> Traceback (most recent call last): >> >> File "", line 1, in >> >> AttributeError: 'str' object has no attribute 'session' >> >> >> >> >> >> >> >> On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder >> >> wrote: >> >> > It is imported from another file. >> >> > >> >> > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai >> >> > >> >> > wrote: >> >> >> >> >> >> The error message you showed us most probably references the db >> >> >> variable. >> >> >> Is db a global variable in the same file? Or is it imported from >> >> >> another >> >> >> module? Can you check its value? >> >> >> >> >> >> >> >> >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder >> >> >> >> >> >> wrote: >> >> >>> >> >> >>> 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 >> >> >>> 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 >> >> >>>> >> >> >>>> wrote: >> >> >>>>> >> >> >>>>> Where does your db variable come from? >> >> >>>>> >> >> >>>>> >> >> >>>>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder >> >> >>>>> >> >> >>>>> 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 >> >> >>>> >> >> >>>> >> >> >>> >> >> > >> >> > >> >> > _______________________________________________ >> >> > Flask mailing list >> >> > Flask at python.org >> >> > https://mail.python.org/mailman/listinfo/flask >> >> > >> > >> > > > From anonymouscodar at gmail.com Sat Feb 25 10:50:01 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sat, 25 Feb 2017 15:50:01 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: Tried everything once again from previous practices but now after removing the line it says: AttributeError: 'dict' object has no attribute 'session' On Sat, Feb 25, 2017 at 3:09 PM, Tom Vaughan wrote: > On Sat, Feb 25, 2017 at 12:07 PM, Anonymous Coder > wrote: > > You mean I should delete following line? > > > > db='db' > > Yes. > > > > > > On Sat, Feb 25, 2017 at 2:41 PM, Tom Vaughan > > wrote: > >> > >> On Sat, Feb 25, 2017 at 11:35 AM, Anonymous Coder > >> wrote: > >> > I think I found it. I really am sorry that I was not clearly lay down > >> > source > >> > code reflecting the issue and thanks for the patience. In __init__ > file > >> > the > >> > previous developer has something like below: > >> > > >> > #File1 > >> > login_manager = LoginManager() > >> > login_manager.init_app(app) > >> > > >> > db = { > >> > 'users': { > >> > "test": ("test", "test") > >> > }, > >> > 'session': {} > >> > } > >> > app.config['DEBUG'] = True > >> > app.config['WTF_CSRF_ENABLED'] = False > >> > app.secret_key = > >> > '\x06\x94\xcf\xaf\xaeB&\xd1s\xa8ZGU\xd2J\xf3\xd6\x12(\xbd\ > xf5\xc3\x858' > >> > > >> > db = 'db' > >> > >> ^^^ Delete this line completely. > >> > >> > >> > > >> > Then in another file he declared the database like below: > >> > > >> > #File 2 > >> > import os > >> > import oursql > >> > from flask import Flask > >> > > >> > app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+ 'root' \ > >> > + ':' + 'test123'+'@'\ > >> > + 'localhost' + '/students' > >> > db = SQLAlchemy(app) > >> > def get_connection(): > >> > return oursql.connect(host='localhost', port='3306', > >> > user='root', > >> > passwd='test123', db='students') > >> > > >> > Now when I need to create any model and need to add tables I do this > in > >> > shell: > >> > > >> > from file2 import db > >> > from somemodelfile import MyNewModel > >> > db.create_all() > >> > > >> > That is how it adds tables. But still I am confuse that why it is not > >> > letting me update fields. > >> > > >> > Except above code there is no representation of data related to how db > >> > needs > >> > to be handled. All the file inside project call database from file1 > but > >> > in > >> > shell I can't use create_db(). When in shell I do like below: > >> > > >> >>>>from file1 import db > >> >>>>db > >> > 'db' #This is the output > >> > > >> > > >> > > >> > On Sat, Feb 25, 2017 at 1:50 PM, Tom Vaughan > >> > wrote: > >> >> > >> >> But how exactly is it imported? Where is it assigned a value? The > >> >> problem seems to be that db is not an instance of a Database object, > >> >> but rather it has been assigned a string. For example: > >> >> > >> >> $ python3 > >> >> Python 3.5.2 (default, Nov 17 2016, 17:05:23) > >> >> [GCC 5.4.0 20160609] on linux > >> >> Type "help", "copyright", "credits" or "license" for more > information. > >> >> >>> db = "foobar" > >> >> >>> db.session > >> >> Traceback (most recent call last): > >> >> File "", line 1, in > >> >> AttributeError: 'str' object has no attribute 'session' > >> >> > >> >> > >> >> > >> >> On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder > >> >> wrote: > >> >> > It is imported from another file. > >> >> > > >> >> > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai > >> >> > > >> >> > wrote: > >> >> >> > >> >> >> The error message you showed us most probably references the db > >> >> >> variable. > >> >> >> Is db a global variable in the same file? Or is it imported from > >> >> >> another > >> >> >> module? Can you check its value? > >> >> >> > >> >> >> > >> >> >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder > >> >> >> > >> >> >> wrote: > >> >> >>> > >> >> >>> 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 > >> >> >>> 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 > >> >> >>>> > >> >> >>>> wrote: > >> >> >>>>> > >> >> >>>>> Where does your db variable come from? > >> >> >>>>> > >> >> >>>>> > >> >> >>>>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder > >> >> >>>>> > >> >> >>>>> 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 > >> >> >>>> > >> >> >>>> > >> >> >>> > >> >> > > >> >> > > >> >> > _______________________________________________ > >> >> > Flask mailing list > >> >> > Flask at python.org > >> >> > https://mail.python.org/mailman/listinfo/flask > >> >> > > >> > > >> > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.david.vaughan at gmail.com Sat Feb 25 11:18:02 2017 From: thomas.david.vaughan at gmail.com (Tom Vaughan) Date: Sat, 25 Feb 2017 13:18:02 -0300 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: On Sat, Feb 25, 2017 at 12:50 PM, Anonymous Coder wrote: > Tried everything once again from previous practices but now after removing > the line it says: > > AttributeError: 'dict' object has no attribute 'session' Alright. It seems I scanned over your examples too hastily. In "File #1" you have: db = { 'users': { "test": ("test", "test") }, 'session': {} } Then in "File #2" you have: db = SQLAlchemy(app) So, in two places you declare a variable called db. The variable db in File #1 is a dict. The variable db in File #2 is an instance of SQLAlchemy. I'd probably rename one of the two at least so it's clear which is which. The error you see is because you're using the db dict from File #1 and trying to access an attribute called "session" (which I assume is a method that exists on the db instance of SQLAlchemy). I think what you want to do is import db from File #2 not File #1. I see the the db dict also contains a key called session. If that's what you really want to use then the correct syntax is db["session"] not db.session. > > On Sat, Feb 25, 2017 at 3:09 PM, Tom Vaughan > wrote: >> >> On Sat, Feb 25, 2017 at 12:07 PM, Anonymous Coder >> wrote: >> > You mean I should delete following line? >> > >> > db='db' >> >> Yes. >> >> >> > >> > On Sat, Feb 25, 2017 at 2:41 PM, Tom Vaughan >> > wrote: >> >> >> >> On Sat, Feb 25, 2017 at 11:35 AM, Anonymous Coder >> >> wrote: >> >> > I think I found it. I really am sorry that I was not clearly lay down >> >> > source >> >> > code reflecting the issue and thanks for the patience. In __init__ >> >> > file >> >> > the >> >> > previous developer has something like below: >> >> > >> >> > #File1 >> >> > login_manager = LoginManager() >> >> > login_manager.init_app(app) >> >> > >> >> > db = { >> >> > 'users': { >> >> > "test": ("test", "test") >> >> > }, >> >> > 'session': {} >> >> > } >> >> > app.config['DEBUG'] = True >> >> > app.config['WTF_CSRF_ENABLED'] = False >> >> > app.secret_key = >> >> > >> >> > '\x06\x94\xcf\xaf\xaeB&\xd1s\xa8ZGU\xd2J\xf3\xd6\x12(\xbd\xf5\xc3\x858' >> >> > >> >> > db = 'db' >> >> >> >> ^^^ Delete this line completely. >> >> >> >> >> >> > >> >> > Then in another file he declared the database like below: >> >> > >> >> > #File 2 >> >> > import os >> >> > import oursql >> >> > from flask import Flask >> >> > >> >> > app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+ 'root' \ >> >> > + ':' + 'test123'+'@'\ >> >> > + 'localhost' + '/students' >> >> > db = SQLAlchemy(app) >> >> > def get_connection(): >> >> > return oursql.connect(host='localhost', port='3306', >> >> > user='root', >> >> > passwd='test123', db='students') >> >> > >> >> > Now when I need to create any model and need to add tables I do this >> >> > in >> >> > shell: >> >> > >> >> > from file2 import db >> >> > from somemodelfile import MyNewModel >> >> > db.create_all() >> >> > >> >> > That is how it adds tables. But still I am confuse that why it is not >> >> > letting me update fields. >> >> > >> >> > Except above code there is no representation of data related to how >> >> > db >> >> > needs >> >> > to be handled. All the file inside project call database from file1 >> >> > but >> >> > in >> >> > shell I can't use create_db(). When in shell I do like below: >> >> > >> >> >>>>from file1 import db >> >> >>>>db >> >> > 'db' #This is the output >> >> > >> >> > >> >> > >> >> > On Sat, Feb 25, 2017 at 1:50 PM, Tom Vaughan >> >> > wrote: >> >> >> >> >> >> But how exactly is it imported? Where is it assigned a value? The >> >> >> problem seems to be that db is not an instance of a Database object, >> >> >> but rather it has been assigned a string. For example: >> >> >> >> >> >> $ python3 >> >> >> Python 3.5.2 (default, Nov 17 2016, 17:05:23) >> >> >> [GCC 5.4.0 20160609] on linux >> >> >> Type "help", "copyright", "credits" or "license" for more >> >> >> information. >> >> >> >>> db = "foobar" >> >> >> >>> db.session >> >> >> Traceback (most recent call last): >> >> >> File "", line 1, in >> >> >> AttributeError: 'str' object has no attribute 'session' >> >> >> >> >> >> >> >> >> >> >> >> On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder >> >> >> wrote: >> >> >> > It is imported from another file. >> >> >> > >> >> >> > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai >> >> >> > >> >> >> > wrote: >> >> >> >> >> >> >> >> The error message you showed us most probably references the db >> >> >> >> variable. >> >> >> >> Is db a global variable in the same file? Or is it imported from >> >> >> >> another >> >> >> >> module? Can you check its value? >> >> >> >> >> >> >> >> >> >> >> >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder >> >> >> >> >> >> >> >> wrote: >> >> >> >>> >> >> >> >>> 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 >> >> >> >>> 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 >> >> >> >>>> >> >> >> >>>> wrote: >> >> >> >>>>> >> >> >> >>>>> Where does your db variable come from? >> >> >> >>>>> >> >> >> >>>>> >> >> >> >>>>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder >> >> >> >>>>> >> >> >> >>>>> 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 >> >> >> >>>> >> >> >> >>>> >> >> >> >>> >> >> >> > >> >> >> > >> >> >> > _______________________________________________ >> >> >> > Flask mailing list >> >> >> > Flask at python.org >> >> >> > https://mail.python.org/mailman/listinfo/flask >> >> >> > >> >> > >> >> > >> > >> > > > From spenceryoung at ufl.edu Sat Feb 25 10:52:47 2017 From: spenceryoung at ufl.edu (Young,Spencer P) Date: Sat, 25 Feb 2017 15:52:47 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: Have you taken a look at the Flask-SQLAlchemy quickstart? Your Database should be an instance of the SQLAlchemy class, not a dictionary. http://flask-sqlalchemy.pocoo.org/2.1/quickstart/ From: Flask [mailto:flask-bounces+spenceryoung=ufl.edu at python.org] On Behalf Of Anonymous Coder Sent: Saturday, February 25, 2017 10:50 AM To: Tom Vaughan Cc: Flask at python.org Subject: Re: [Flask] Updating database fields from views Tried everything once again from previous practices but now after removing the line it says: AttributeError: 'dict' object has no attribute 'session' On Sat, Feb 25, 2017 at 3:09 PM, Tom Vaughan > wrote: On Sat, Feb 25, 2017 at 12:07 PM, Anonymous Coder > wrote: > You mean I should delete following line? > > db='db' Yes. > > On Sat, Feb 25, 2017 at 2:41 PM, Tom Vaughan > > wrote: >> >> On Sat, Feb 25, 2017 at 11:35 AM, Anonymous Coder >> > wrote: >> > I think I found it. I really am sorry that I was not clearly lay down >> > source >> > code reflecting the issue and thanks for the patience. In __init__ file >> > the >> > previous developer has something like below: >> > >> > #File1 >> > login_manager = LoginManager() >> > login_manager.init_app(app) >> > >> > db = { >> > 'users': { >> > "test": ("test", "test") >> > }, >> > 'session': {} >> > } >> > app.config['DEBUG'] = True >> > app.config['WTF_CSRF_ENABLED'] = False >> > app.secret_key = >> > '\x06\x94\xcf\xaf\xaeB&\xd1s\xa8ZGU\xd2J\xf3\xd6\x12(\xbd\xf5\xc3\x858' >> > >> > db = 'db' >> >> ^^^ Delete this line completely. >> >> >> > >> > Then in another file he declared the database like below: >> > >> > #File 2 >> > import os >> > import oursql >> > from flask import Flask >> > >> > app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+ 'root' \ >> > + ':' + 'test123'+'@'\ >> > + 'localhost' + '/students' >> > db = SQLAlchemy(app) >> > def get_connection(): >> > return oursql.connect(host='localhost', port='3306', >> > user='root', >> > passwd='test123', db='students') >> > >> > Now when I need to create any model and need to add tables I do this in >> > shell: >> > >> > from file2 import db >> > from somemodelfile import MyNewModel >> > db.create_all() >> > >> > That is how it adds tables. But still I am confuse that why it is not >> > letting me update fields. >> > >> > Except above code there is no representation of data related to how db >> > needs >> > to be handled. All the file inside project call database from file1 but >> > in >> > shell I can't use create_db(). When in shell I do like below: >> > >> >>>>from file1 import db >> >>>>db >> > 'db' #This is the output >> > >> > >> > >> > On Sat, Feb 25, 2017 at 1:50 PM, Tom Vaughan >> > > wrote: >> >> >> >> But how exactly is it imported? Where is it assigned a value? The >> >> problem seems to be that db is not an instance of a Database object, >> >> but rather it has been assigned a string. For example: >> >> >> >> $ python3 >> >> Python 3.5.2 (default, Nov 17 2016, 17:05:23) >> >> [GCC 5.4.0 20160609] on linux >> >> Type "help", "copyright", "credits" or "license" for more information. >> >> >>> db = "foobar" >> >> >>> db.session >> >> Traceback (most recent call last): >> >> File "", line 1, in >> >> AttributeError: 'str' object has no attribute 'session' >> >> >> >> >> >> >> >> On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder >> >> > wrote: >> >> > It is imported from another file. >> >> > >> >> > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai >> >> > > >> >> > wrote: >> >> >> >> >> >> The error message you showed us most probably references the db >> >> >> variable. >> >> >> Is db a global variable in the same file? Or is it imported from >> >> >> another >> >> >> module? Can you check its value? >> >> >> >> >> >> >> >> >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder >> >> >> > >> >> >> wrote: >> >> >>> >> >> >>> 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 >> >> >>> > 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 >> >> >>>> > >> >> >>>> wrote: >> >> >>>>> >> >> >>>>> Where does your db variable come from? >> >> >>>>> >> >> >>>>> >> >> >>>>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder >> >> >>>>> > >> >> >>>>> 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 >> >> >>>> >> >> >>>> >> >> >>> >> >> > >> >> > >> >> > _______________________________________________ >> >> > Flask mailing list >> >> > Flask at python.org >> >> > https://mail.python.org/mailman/listinfo/flask >> >> > >> > >> > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anonymouscodar at gmail.com Sun Feb 26 00:18:20 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sun, 26 Feb 2017 05:18:20 +0000 Subject: [Flask] Updating database fields from views In-Reply-To: References: Message-ID: I imported both in shell and with I printed the one from file2 shows SQlAlchemy instance of DB. So what I did in my views that I left file1.db as it is in my views just to make sure if it is applied to anything (3900 lines of code in views) it won't be disturbed. Then I imported file2 db like below. from file2 import db as dbase Now it is saving models perfectly. I am really thankful to you guys for help. This group rocks. On Sat, Feb 25, 2017 at 4:18 PM, Tom Vaughan wrote: > On Sat, Feb 25, 2017 at 12:50 PM, Anonymous Coder > wrote: > > Tried everything once again from previous practices but now after > removing > > the line it says: > > > > AttributeError: 'dict' object has no attribute 'session' > > Alright. It seems I scanned over your examples too hastily. In "File > #1" you have: > > db = { > 'users': { > "test": ("test", "test") > }, > 'session': {} > } > > Then in "File #2" you have: > > db = SQLAlchemy(app) > > So, in two places you declare a variable called db. The variable db in > File #1 is a dict. The variable db in File #2 is an instance of > SQLAlchemy. I'd probably rename one of the two at least so it's clear > which is which. > > The error you see is because you're using the db dict from File #1 and > trying to access an attribute called "session" (which I assume is a > method that exists on the db instance of SQLAlchemy). I think what you > want to do is import db from File #2 not File #1. I see the the db > dict also contains a key called session. If that's what you really > want to use then the correct syntax is db["session"] not db.session. > > > > > > On Sat, Feb 25, 2017 at 3:09 PM, Tom Vaughan > > wrote: > >> > >> On Sat, Feb 25, 2017 at 12:07 PM, Anonymous Coder > >> wrote: > >> > You mean I should delete following line? > >> > > >> > db='db' > >> > >> Yes. > >> > >> > >> > > >> > On Sat, Feb 25, 2017 at 2:41 PM, Tom Vaughan > >> > wrote: > >> >> > >> >> On Sat, Feb 25, 2017 at 11:35 AM, Anonymous Coder > >> >> wrote: > >> >> > I think I found it. I really am sorry that I was not clearly lay > down > >> >> > source > >> >> > code reflecting the issue and thanks for the patience. In __init__ > >> >> > file > >> >> > the > >> >> > previous developer has something like below: > >> >> > > >> >> > #File1 > >> >> > login_manager = LoginManager() > >> >> > login_manager.init_app(app) > >> >> > > >> >> > db = { > >> >> > 'users': { > >> >> > "test": ("test", "test") > >> >> > }, > >> >> > 'session': {} > >> >> > } > >> >> > app.config['DEBUG'] = True > >> >> > app.config['WTF_CSRF_ENABLED'] = False > >> >> > app.secret_key = > >> >> > > >> >> > '\x06\x94\xcf\xaf\xaeB&\xd1s\xa8ZGU\xd2J\xf3\xd6\x12(\xbd\ > xf5\xc3\x858' > >> >> > > >> >> > db = 'db' > >> >> > >> >> ^^^ Delete this line completely. > >> >> > >> >> > >> >> > > >> >> > Then in another file he declared the database like below: > >> >> > > >> >> > #File 2 > >> >> > import os > >> >> > import oursql > >> >> > from flask import Flask > >> >> > > >> >> > app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://'+ 'root' \ > >> >> > + ':' + 'test123'+'@'\ > >> >> > + 'localhost' + '/students' > >> >> > db = SQLAlchemy(app) > >> >> > def get_connection(): > >> >> > return oursql.connect(host='localhost', port='3306', > >> >> > user='root', > >> >> > passwd='test123', db='students') > >> >> > > >> >> > Now when I need to create any model and need to add tables I do > this > >> >> > in > >> >> > shell: > >> >> > > >> >> > from file2 import db > >> >> > from somemodelfile import MyNewModel > >> >> > db.create_all() > >> >> > > >> >> > That is how it adds tables. But still I am confuse that why it is > not > >> >> > letting me update fields. > >> >> > > >> >> > Except above code there is no representation of data related to how > >> >> > db > >> >> > needs > >> >> > to be handled. All the file inside project call database from file1 > >> >> > but > >> >> > in > >> >> > shell I can't use create_db(). When in shell I do like below: > >> >> > > >> >> >>>>from file1 import db > >> >> >>>>db > >> >> > 'db' #This is the output > >> >> > > >> >> > > >> >> > > >> >> > On Sat, Feb 25, 2017 at 1:50 PM, Tom Vaughan > >> >> > wrote: > >> >> >> > >> >> >> But how exactly is it imported? Where is it assigned a value? The > >> >> >> problem seems to be that db is not an instance of a Database > object, > >> >> >> but rather it has been assigned a string. For example: > >> >> >> > >> >> >> $ python3 > >> >> >> Python 3.5.2 (default, Nov 17 2016, 17:05:23) > >> >> >> [GCC 5.4.0 20160609] on linux > >> >> >> Type "help", "copyright", "credits" or "license" for more > >> >> >> information. > >> >> >> >>> db = "foobar" > >> >> >> >>> db.session > >> >> >> Traceback (most recent call last): > >> >> >> File "", line 1, in > >> >> >> AttributeError: 'str' object has no attribute 'session' > >> >> >> > >> >> >> > >> >> >> > >> >> >> On Sat, Feb 25, 2017 at 9:40 AM, Anonymous Coder > >> >> >> wrote: > >> >> >> > It is imported from another file. > >> >> >> > > >> >> >> > On Sat, Feb 25, 2017 at 11:51 AM, Gergely Polonkai > >> >> >> > > >> >> >> > wrote: > >> >> >> >> > >> >> >> >> The error message you showed us most probably references the db > >> >> >> >> variable. > >> >> >> >> Is db a global variable in the same file? Or is it imported > from > >> >> >> >> another > >> >> >> >> module? Can you check its value? > >> >> >> >> > >> >> >> >> > >> >> >> >> On Sat, Feb 25, 2017, 12:46 Anonymous Coder > >> >> >> >> > >> >> >> >> wrote: > >> >> >> >>> > >> >> >> >>> 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 > >> >> >> >>> 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 > >> >> >> >>>> > >> >> >> >>>> wrote: > >> >> >> >>>>> > >> >> >> >>>>> Where does your db variable come from? > >> >> >> >>>>> > >> >> >> >>>>> > >> >> >> >>>>> On Sat, Feb 25, 2017, 08:36 Anonymous Coder > >> >> >> >>>>> > >> >> >> >>>>> 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 > >> >> >> >>>> > >> >> >> >>>> > >> >> >> >>> > >> >> >> > > >> >> >> > > >> >> >> > _______________________________________________ > >> >> >> > Flask mailing list > >> >> >> > Flask at python.org > >> >> >> > https://mail.python.org/mailman/listinfo/flask > >> >> >> > > >> >> > > >> >> > > >> > > >> > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anonymouscodar at gmail.com Sun Feb 26 04:18:42 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Sun, 26 Feb 2017 09:18:42 +0000 Subject: [Flask] Saving Stripe JSON objects in Flask Database Message-ID: Hi, I am having trouble saving Stripe json objects in Flask Database. Just need to save customer.id and expiry date from the view below: @app.route('/yearlychargedrec', methods=['GET', 'POST']) def yearly_charged_rec(): if not user_authorized(): return redirect('/') 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( student_email=request.form['stripeEmail'], is_active=True, package_type='yearlyrec' ) dbase.session.add(package) dbase.session.commit() except stripe.error.CardError as e: body = e.json_body err = body['error'] return render_template('/profile/charge/monthlycharge.html') -------------- next part -------------- An HTML attachment was scrubbed... URL: From thomas.david.vaughan at gmail.com Sun Feb 26 08:27:52 2017 From: thomas.david.vaughan at gmail.com (Tom Vaughan) Date: Sun, 26 Feb 2017 10:27:52 -0300 Subject: [Flask] Saving Stripe JSON objects in Flask Database In-Reply-To: References: Message-ID: On Sun, Feb 26, 2017 at 6:18 AM, Anonymous Coder wrote: > Hi, > > I am having trouble saving Stripe json objects in Flask Database. Just need > to save customer.id and expiry date from the view below: I don't see an expiry date below. I don't see where you try to save the customer id. What do you mean by "trouble"? Do you mean you've encountered an error, or that you don't know how and you'd like us to do the work for you? The former we can help with. The latter is probably beyond the scope of this list. > > @app.route('/yearlychargedrec', methods=['GET', 'POST']) > def yearly_charged_rec(): > if not user_authorized(): > return redirect('/') > if request.method == 'POST': > stripe_token = request.form['stripeToken'] > email = request.form['stripeEmail'] > customer = stripe.Customer.create( > email=email, > source=request.form['stripeToken'] See stripe_token variable above. > ) > try: > subscription = stripe.Subscription.create( > customer=customer.id, > plan="yearlyrec", > ) subscription is unused. > > package = Package( > student_email=request.form['stripeEmail'], See email variable above. > is_active=True, > package_type='yearlyrec' > ) > dbase.session.add(package) > dbase.session.commit() > except stripe.error.CardError as e: > body = e.json_body > err = body['error'] body and err are unused. This error is ignored. > > return render_template('/profile/charge/monthlycharge.html') monthlycharge.html within a yearly charge handler? > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > From anonymouscodar at gmail.com Sun Feb 26 22:41:56 2017 From: anonymouscodar at gmail.com (Anonymous Coder) Date: Mon, 27 Feb 2017 03:41:56 +0000 Subject: [Flask] Saving Stripe JSON objects in Flask Database In-Reply-To: References: Message-ID: I have a Package model where I am trying to update fields below but for expiry and due date I don't know how to implement. Objective is to retrieve due date and expiry dates from stripe subscriptions. class Package(db.Model): __tablename__ = 'package' id = db.Column(db.Integer, primary_key=True, autoincrement=True) student_id = db.Column(db.Integer, ForeignKey('student_profile.id')) stripe_id = db.Column(db.String(45)) student_email = db.Column(db.String(20)) subscription_date = db.Column(db.DateTime, default=today) expiry_date = db.Column(db.DateTime, default=deadline) expiry_date = db.Column(db.DateTime, default=deadline) is_active = db.Column(db.Boolean, default=True) package_type = db.Column(db.String(45), default='NOPACKAGE') package_price = db.Column(db.Integer) coupon = db.Column(db.String(12)) def __init__(self, **kwargs): for key, value in kwargs.items(): setattr(self, key, value) On Sun, Feb 26, 2017 at 1:27 PM, Tom Vaughan wrote: > On Sun, Feb 26, 2017 at 6:18 AM, Anonymous Coder > wrote: > > Hi, > > > > I am having trouble saving Stripe json objects in Flask Database. Just > need > > to save customer.id and expiry date from the view below: > > I don't see an expiry date below. I don't see where you try to save > the customer id. What do you mean by "trouble"? Do you mean you've > encountered an error, or that you don't know how and you'd like us to > do the work for you? The former we can help with. The latter is > probably beyond the scope of this list. > > > > > > @app.route('/yearlychargedrec', methods=['GET', 'POST']) > > def yearly_charged_rec(): > > if not user_authorized(): > > return redirect('/') > > if request.method == 'POST': > > stripe_token = request.form['stripeToken'] > > email = request.form['stripeEmail'] > > customer = stripe.Customer.create( > > email=email, > > source=request.form['stripeToken'] > > See stripe_token variable above. > > > ) > > try: > > subscription = stripe.Subscription.create( > > customer=customer.id, > > plan="yearlyrec", > > ) > > subscription is unused. > > > > > package = Package( > > student_email=request.form['stripeEmail'], > > See email variable above. > > > is_active=True, > > package_type='yearlyrec' > > ) > > dbase.session.add(package) > > dbase.session.commit() > > except stripe.error.CardError as e: > > body = e.json_body > > err = body['error'] > > body and err are unused. This error is ignored. > > > > > return render_template('/profile/charge/monthlycharge.html') > > monthlycharge.html within a yearly charge handler? > > > > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ernstki at mail.uc.edu Sat Feb 25 19:38:54 2017 From: ernstki at mail.uc.edu (Kevin Ernst) Date: Sat, 25 Feb 2017 19:38:54 -0500 Subject: [Flask] Trimming mailing list replies In-Reply-To: References: Message-ID: May I make a modest request: that we try to trim our replies to just what's absolutely necessary for context? https://en.wikipedia.org/wiki/Posting_style#Trimming_and_reformatting It takes just a couple of seconds to select and delete the parts you don't need, even on a mobile device. I know that mail clients like Outlook, Apple Mail, and mobiles actively hide enclosed replies (and are thus part of the problem), but anyone who gets the digest version of the Flask mailing list will see this http://imgur.com/a/19rCw multiplied by however messages are in the digest. This impacts the signal-to-noise ratio of the digest dramatically. Thanks for your consideration. --Kevin From davidism at gmail.com Mon Feb 27 11:08:19 2017 From: davidism at gmail.com (David Lord) Date: Mon, 27 Feb 2017 08:08:19 -0800 Subject: [Flask] Flask-SQLAlchemy 2.2 released Message-ID: After a long wait, we've released Flask-SQLAlchemy 2.2 with essential bug fixes from the last few years. Sorry for the long wait! https://github.com/mitsuhiko/flask-sqlalchemy/releases/tag/2.2 Install or upgrade with pip: pip install -U Flask-SQLAlchemy Changelog: - Minimum SQLAlchemy version is 0.8 due to use of ``sqlalchemy.inspect``. - Added support for custom ``query_class`` and ``model_class`` as args to the ``SQLAlchemy`` constructor. (`#328`_) - Allow listening to SQLAlchemy events on ``db.session``. (`#364`_) - Allow ``__bind_key__`` on abstract models. (`#373`_) - Allow ``SQLALCHEMY_ECHO`` to be a string. (`#409`_) - Warn when ``SQLALCHEMY_DATABASE_URI`` is not set. (`#443`_) - Don't let pagination generate invalid page numbers. (`#460`_) - Drop support of Flask < 0.10. This means the db session is always tied to the app context and its teardown event. (`#461`_) - Tablename generation logic no longer accesses class properties unless they are ``declared_attr``. (`#467`_) .. _#328: https://github.com/mitsuhiko/flask-sqlalchemy/pull/328 .. _#364: https://github.com/mitsuhiko/flask-sqlalchemy/pull/364 .. _#373: https://github.com/mitsuhiko/flask-sqlalchemy/pull/373 .. _#409: https://github.com/mitsuhiko/flask-sqlalchemy/pull/409 .. _#443: https://github.com/mitsuhiko/flask-sqlalchemy/pull/443 .. _#460: https://github.com/mitsuhiko/flask-sqlalchemy/pull/460 .. _#461: https://github.com/mitsuhiko/flask-sqlalchemy/pull/461 .. _#467: https://github.com/mitsuhiko/flask-sqlalchemy/pull/467 --- We are still working towards larger changes in a 3.0 release, and would appreciate any help, big or small. Whether it's triaging issues, updating and improving the docs, finding bugs, or squashing bugs, everything helps! --- Finally, if you want to, please retweet this to spread the word to more developers: https://twitter.com/davidism/status/836243545409241088 Again, thank you for your continued support and patience! -------------- next part -------------- An HTML attachment was scrubbed... URL: From badrihippo at gmail.com Tue Feb 28 03:53:39 2017 From: badrihippo at gmail.com (Hippo) Date: Tue, 28 Feb 2017 08:53:39 +0000 Subject: [Flask] Trimming mailing list replies In-Reply-To: References: Message-ID: Agreed! I do this as a habit nowadays. It would be nice if there were settings to automatically remove (or rather, not add) quoted text. I know desktop Gmail has a setting, though the mobile apps don't. FYI, the Inbox app includes it by default but doesn't show it to you: you have to start typing, close the draft, and then open it again to backspace. I haven't used many other services; perhaps someone else could share details on those? -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip.montanaro at gmail.com Tue Feb 28 14:07:33 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 28 Feb 2017 13:07:33 -0600 Subject: [Flask] JSON is always pretty Message-ID: I just started using Flask (v 0.12 in a Conda Python 2.7 environment) as a tool to implement a RESTful server. So far, it looks great. I'm just debugging things and working with small output, so it's not a huge deal just now, but no matter what I do, flask.jsonify() seems to always pretty print the returned JSON. I've been running my application like this: FLASK_DEBUG=1 FLASK_APP=map.py flask run then in map.py, I tweak the config parameters like so: app = Flask(__name__) DEBUG = os.environ.get("FLASK_DEBUG") == "1" app.config.update(DEBUG=DEBUG, JSON_PRETTYPRINT_REGULAR=DEBUG) Even if I leave FLASK_DEBUG off the command line or explicitly set it to "0", the JSON comes out formatted. Thinking I might have misread the documentation of JSON_PRETTYPRINT_REGULAR, I changed the update call to app.config.update(DEBUG=DEBUG, JSON_PRETTYPRINT_REGULAR=not DEBUG) but that had no effect. The output is still pretty. Am I supposed to be unable to explicitly override JSON pretty printing at the level of flask.jsonify()? Do I need to drop down a level to flask.json.dumps() (where it also seems to be uncontrollable, but always condensed)? Thanks, Skip Montanaro From wright8191 at gmail.com Tue Feb 28 14:15:50 2017 From: wright8191 at gmail.com (Harrison Wright) Date: Tue, 28 Feb 2017 13:15:50 -0600 Subject: [Flask] JSON is always pretty In-Reply-To: References: Message-ID: Looks like you using the wrong config name? "JSONIFY" not "JSON". The following works for me. app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False On Tue, Feb 28, 2017 at 1:07 PM, Skip Montanaro wrote: > I just started using Flask (v 0.12 in a Conda Python 2.7 environment) > as a tool to implement a RESTful server. So far, it looks great. I'm > just debugging things and working with small output, so it's not a > huge deal just now, but no matter what I do, flask.jsonify() seems to > always pretty print the returned JSON. I've been running my > application like this: > > FLASK_DEBUG=1 FLASK_APP=map.py flask run > > then in map.py, I tweak the config parameters like so: > > app = Flask(__name__) > > DEBUG = os.environ.get("FLASK_DEBUG") == "1" > app.config.update(DEBUG=DEBUG, JSON_PRETTYPRINT_REGULAR=DEBUG) > > Even if I leave FLASK_DEBUG off the command line or explicitly set it > to "0", the JSON comes out formatted. Thinking I might have misread > the documentation of JSON_PRETTYPRINT_REGULAR, I changed the update > call to > > app.config.update(DEBUG=DEBUG, JSON_PRETTYPRINT_REGULAR=not DEBUG) > > but that had no effect. The output is still pretty. > > Am I supposed to be unable to explicitly override JSON pretty printing > at the level of flask.jsonify()? Do I need to drop down a level to > flask.json.dumps() (where it also seems to be uncontrollable, but > always condensed)? > > Thanks, > > Skip Montanaro > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip.montanaro at gmail.com Tue Feb 28 15:00:59 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 28 Feb 2017 14:00:59 -0600 Subject: [Flask] JSON is always pretty In-Reply-To: References: Message-ID: On Tue, Feb 28, 2017 at 1:15 PM, Harrison Wright wrote: > Looks like you using the wrong config name? "JSONIFY" not "JSON". Duh, thanks. In my defense, you have to admit that config name is a real mouthful. A few characters more-or-less are easy to miss. ;-) Skip