From orestis at oioannou.com Tue Sep 1 00:08:54 2015 From: orestis at oioannou.com (Orestis Ioannou) Date: Tue, 01 Sep 2015 00:08:54 +0200 Subject: [Flask] similar to django-reversion Message-ID: <55E4D076.3070103@oioannou.com> Hello, Is there an extension that implements the functionalities of django reversion? What i am interested in is an extension that will enable going through different versions of a model (i.e an article), comparing two revisions etc. Cheers, Orestis -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From hunter at zeta.pm Tue Sep 1 15:23:11 2015 From: hunter at zeta.pm (Aleksandr Tihomirov) Date: Tue, 1 Sep 2015 16:23:11 +0300 Subject: [Flask] similar to django-reversion In-Reply-To: <55E4D076.3070103@oioannou.com> References: <55E4D076.3070103@oioannou.com> Message-ID: <55E5A6BF.4080108@zeta.pm> Hello, I am fairly new to the whole mailing list thing so I might've messed up somewhere. I think what you might be interested in is SQLAlchemy-Continuum extension, I have not personally used this and it might take some effort to use in Flask environment but this is the closest to wiki-style revisions. From jicenhower at yahoo.com Tue Sep 1 16:21:49 2015 From: jicenhower at yahoo.com (Jim Icenhower) Date: Tue, 1 Sep 2015 14:21:49 +0000 (UTC) Subject: [Flask] Querying flask-appbuilder model using sqlalchemy Message-ID: <2145575918.4132457.1441117309879.JavaMail.yahoo@mail.yahoo.com> Hi all, I'm creating an app using Flask-Appbuilder and trying to use Flask-Excel which is pyexcel to export records based on a class named Event implementing the Model class. I can use the pyexcel?I'd like to do this the pyexcel make_response_from_tables() method but I want to control the order in which the columns are output. I will eventually also want to filter the output records so I need some control over the output. I would like to do this the most correct way, hopefully using the Event class to return the data. Can anyone give me a nudge in the right direction to do this? The current error I'm receiving is "AttributeError: 'Query' object has no attribute 'query'". What should I do or where should I look for detailed guidence? Thanks! In models.py: (snipped of imports)from sqlalchemy import Column, Integer, Float, String, ForeignKey, Text, Datefrom flask.ext.appbuilder import Model class Event(Model):? ? EventID = Column(Integer, primary_key=True)? ? Name = Column(String(100), unique=True, nullable=False)? ? Description = Column(Text(1000), unique=True, nullable=False)? ? BeginDate = Column(Date, unique=True, nullable=False)? ? EndDate = Column(Date, unique=True, nullable=False) ? ? def __repr__(self):? ? ? ? return self.Name In views.py: (snippet of imports)from flask.ext import excelfrom pyexcel.ext import xlsx, xls @app.route("/export_events", methods=['GET'])def export_events():? ? datamodel = SQLAInterface(Event)? ? column_names=['EventId','Description']? ? db.session.query(Event).query.all()? ? return excel.make_response_from_query_sets(query_sets, column_names, "xls") Thanks for any help! ? ??Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From orestis at oioannou.com Wed Sep 2 00:03:25 2015 From: orestis at oioannou.com (Orestis Ioannou) Date: Wed, 02 Sep 2015 00:03:25 +0200 Subject: [Flask] similar to django-reversion In-Reply-To: <55E5A6BF.4080108@zeta.pm> References: <55E4D076.3070103@oioannou.com> <55E5A6BF.4080108@zeta.pm> Message-ID: <55E620AD.7010608@oioannou.com> On 09/01/2015 03:23 PM, Aleksandr Tihomirov wrote: > Hello, > > I am fairly new to the whole mailing list thing so I might've messed up > somewhere. > > I think what you might be interested in is SQLAlchemy-Continuum > extension, I have not personally used this and it might take some effort > to use in Flask environment but this is the closest to wiki-style > revisions. > Thanks for pointing me there. It looks like that it will do the job. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 801 bytes Desc: OpenPGP digital signature URL: From connollymorg at gmail.com Wed Sep 2 14:10:31 2015 From: connollymorg at gmail.com (Morgan Connolly) Date: Wed, 2 Sep 2015 17:40:31 +0530 Subject: [Flask] Flask-Security authentication in JS Message-ID: I have a Flask app that uses Flask-Security for authentication, which is storing authentication details in cookies on the client side. Currently, it is a static app rendered using Jinja templates, but now I want to implement some features which require access to protected resources dynamically via JavaScript. If I send a request using JavaScript to a URL, the cookies won't be transmitted. If I want to transmit the username/password with each request, I will have to pass it to Jinja in cleartext. I'm at a total loss here, and I do not know what to do. Can somebody point me in the right direction? Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From coreybrett at gmail.com Wed Sep 2 14:42:14 2015 From: coreybrett at gmail.com (Corey Boyle) Date: Wed, 2 Sep 2015 08:42:14 -0400 Subject: [Flask] Flask-Security authentication in JS In-Reply-To: References: Message-ID: Maybe this could help. https://github.com/miguelgrinberg/flasky/issues/60 On Wed, Sep 2, 2015 at 8:10 AM, Morgan Connolly wrote: > I have a Flask app that uses Flask-Security for authentication, which is > storing authentication details in cookies on the client side. Currently, it > is a static app rendered using Jinja templates, but now I want to implement > some features which require access to protected resources dynamically via > JavaScript. > > If I send a request using JavaScript to a URL, the cookies won't be > transmitted. If I want to transmit the username/password with each request, > I will have to pass it to Jinja in cleartext. > > I'm at a total loss here, and I do not know what to do. Can somebody point > me in the right direction? > > Cheers > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > From scott.werner.vt at gmail.com Wed Sep 2 14:49:11 2015 From: scott.werner.vt at gmail.com (Scott Werner) Date: Wed, 2 Sep 2015 08:49:11 -0400 Subject: [Flask] Flask-Security authentication in JS In-Reply-To: References: Message-ID: The author of Flask-Security also created the following extension https://github.com/mattupstate/flask-jwt. See his comments on https://github.com/mattupstate/flask-security/issues/215. On Wed, Sep 2, 2015 at 8:42 AM, Corey Boyle wrote: > Maybe this could help. > https://github.com/miguelgrinberg/flasky/issues/60 > > On Wed, Sep 2, 2015 at 8:10 AM, Morgan Connolly > wrote: > > I have a Flask app that uses Flask-Security for authentication, which is > > storing authentication details in cookies on the client side. Currently, > it > > is a static app rendered using Jinja templates, but now I want to > implement > > some features which require access to protected resources dynamically via > > JavaScript. > > > > If I send a request using JavaScript to a URL, the cookies won't be > > transmitted. If I want to transmit the username/password with each > request, > > I will have to pass it to Jinja in cleartext. > > > > I'm at a total loss here, and I do not know what to do. Can somebody > point > > me in the right direction? > > > > Cheers > > > > _______________________________________________ > > 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 > -- Scott Werner scott.werner.vt at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From projetmbc at gmail.com Wed Sep 2 14:48:19 2015 From: projetmbc at gmail.com (Christophe Bal) Date: Wed, 2 Sep 2015 14:48:19 +0200 Subject: [Flask] Flask-Security authentication in JS In-Reply-To: References: Message-ID: Hello (sorry Corey Boyle). Can you give a more concrete example of the thing you want to achieve ? *Christophe BAL* *Enseignant de math?matiques en Lyc?e **et d?veloppeur Python amateur* *---* *French math teacher in a "Lyc?e" **and **Python **amateur developer* 2015-09-02 14:10 GMT+02:00 Morgan Connolly : > I have a Flask app that uses Flask-Security for authentication, which is > storing authentication details in cookies on the client side. Currently, it > is a static app rendered using Jinja templates, but now I want to implement > some features which require access to protected resources dynamically via > JavaScript. > > If I send a request using JavaScript to a URL, the cookies won't be > transmitted. If I want to transmit the username/password with each request, > I will have to pass it to Jinja in cleartext. > > I'm at a total loss here, and I do not know what to do. Can somebody point > me in the right direction? > > Cheers > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fededelgado at outlook.com Thu Sep 3 01:28:25 2015 From: fededelgado at outlook.com (Federico Delgado Doyle) Date: Wed, 2 Sep 2015 16:28:25 -0700 Subject: [Flask] Flask-Security authentication in JS In-Reply-To: References: Message-ID: Hi Morgan, I don't know about Flask-Security. But cookies should transmit regardless if the browser sent a post or get or a javascript http request caused it. Have you actually seen that the cookie is not traveling when using jquery ajax or whatever you use? Cheers, Federico Date: Wed, 2 Sep 2015 17:40:31 +0530 From: connollymorg at gmail.com To: flask at python.org Subject: [Flask] Flask-Security authentication in JS I have a Flask app that uses Flask-Security for authentication, which is storing authentication details in cookies on the client side. Currently, it is a static app rendered using Jinja templates, but now I want to implement some features which require access to protected resources dynamically via JavaScript. If I send a request using JavaScript to a URL, the cookies won't be transmitted. If I want to transmit the username/password with each request, I will have to pass it to Jinja in cleartext. I'm at a total loss here, and I do not know what to do. Can somebody point me in the right direction? Cheers _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From connollymorg at gmail.com Thu Sep 3 08:55:50 2015 From: connollymorg at gmail.com (Morgan Connolly) Date: Thu, 3 Sep 2015 12:25:50 +0530 Subject: [Flask] Flask-Security authentication in JS In-Reply-To: References: Message-ID: Hey! Thanks so much Corey, Scott, Christophe and Federico. I didn't know that the browser would transmit cookies even if I used JavaScript, having never worked on a dynamic website before. I just tried adding the JavaScript, and without having to do any other work, it works how I want it to. Once again, thank you all for your help! Cheers On Thu, Sep 3, 2015 at 4:58 AM, Federico Delgado Doyle < fededelgado at outlook.com> wrote: > Hi Morgan, > > I don't know about Flask-Security. But cookies should transmit regardless > if the browser sent a post or get or a javascript http request caused it. > > Have you actually seen that the cookie is not traveling when using jquery > ajax or whatever you use? > > Cheers, > > Federico > > ------------------------------ > Date: Wed, 2 Sep 2015 17:40:31 +0530 > From: connollymorg at gmail.com > To: flask at python.org > Subject: [Flask] Flask-Security authentication in JS > > > I have a Flask app that uses Flask-Security for authentication, which is > storing authentication details in cookies on the client side. Currently, it > is a static app rendered using Jinja templates, but now I want to implement > some features which require access to protected resources dynamically via > JavaScript. > > If I send a request using JavaScript to a URL, the cookies won't be > transmitted. If I want to transmit the username/password with each request, > I will have to pass it to Jinja in cleartext. > > I'm at a total loss here, and I do not know what to do. Can somebody point > me in the right direction? > > Cheers > > _______________________________________________ Flask mailing list > Flask at python.org https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hunter at zeta.pm Thu Sep 3 11:56:10 2015 From: hunter at zeta.pm (zeta) Date: Thu, 03 Sep 2015 12:56:10 +0300 Subject: [Flask] Querying flask-appbuilder model using sqlalchemy Message-ID: I think your issue is caused by: > db.session.query(Event).query.all() Try: db.session.query(Event).all() -------------- next part -------------- An HTML attachment was scrubbed... URL: From jicenhower at yahoo.com Thu Sep 3 14:34:13 2015 From: jicenhower at yahoo.com (Jim Icenhower) Date: Thu, 3 Sep 2015 12:34:13 +0000 (UTC) Subject: [Flask] Flask Digest, Vol 3, Issue 4 In-Reply-To: References: Message-ID: <395746138.955062.1441283653823.JavaMail.yahoo@mail.yahoo.com> Thanks you Zeta. That solved it. Now I'm one step closer to my next question! I work in Java professionally and I'm really enjoying Python/Flask/Appbuilder. Thanks again!?Jim From: "flask-request at python.org" To: flask at python.org Sent: Thursday, September 3, 2015 5:00 AM Subject: Flask Digest, Vol 3, Issue 4 Send Flask mailing list submissions to ??? flask at python.org To subscribe or unsubscribe via the World Wide Web, visit ??? https://mail.python.org/mailman/listinfo/flask or, via email, send a message with subject or body 'help' to ??? flask-request at python.org You can reach the person managing the list at ??? flask-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Flask digest..." Today's Topics: ? 1. Re: Flask-Security authentication in JS (Morgan Connolly) ? 2.? Querying flask-appbuilder model using sqlalchemy (zeta) ---------------------------------------------------------------------- Message: 1 Date: Thu, 3 Sep 2015 12:25:50 +0530 From: Morgan Connolly To: Federico Delgado Doyle Cc: "flask at python.org" Subject: Re: [Flask] Flask-Security authentication in JS Message-ID: ??? Content-Type: text/plain; charset="utf-8" Hey! Thanks so much Corey, Scott, Christophe and Federico. I didn't know that the browser would transmit cookies even if I used JavaScript, having never worked on a dynamic website before. I just tried adding the JavaScript, and without having to do any other work, it works how I want it to. Once again, thank you all for your help! Cheers On Thu, Sep 3, 2015 at 4:58 AM, Federico Delgado Doyle < fededelgado at outlook.com> wrote: > Hi Morgan, > > I don't know about Flask-Security. But cookies should transmit regardless > if the browser sent a post or get? or a javascript http request caused it. > > Have you actually seen that the cookie is not traveling when using jquery > ajax or whatever you use? > > Cheers, > > Federico > > ------------------------------ > Date: Wed, 2 Sep 2015 17:40:31 +0530 > From: connollymorg at gmail.com > To: flask at python.org > Subject: [Flask] Flask-Security authentication in JS > > > I have a Flask app that uses Flask-Security for authentication, which is > storing authentication details in cookies on the client side. Currently, it > is a static app rendered using Jinja templates, but now I want to implement > some features which require access to protected resources dynamically via > JavaScript. > > If I send a request using JavaScript to a URL, the cookies won't be > transmitted. If I want to transmit the username/password with each request, > I will have to pass it to Jinja in cleartext. > > I'm at a total loss here, and I do not know what to do. Can somebody point > me in the right direction? > > Cheers > > _______________________________________________ Flask mailing list > Flask at python.org https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 2 Date: Thu, 03 Sep 2015 12:56:10 +0300 From: zeta To: flask at python.org Subject: [Flask]? Querying flask-appbuilder model using sqlalchemy Message-ID: Content-Type: text/plain; charset="us-ascii" I think your issue is caused by: > db.session.query(Event).query.all() Try: db.session.query(Event).all() -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Subject: Digest Footer _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask ------------------------------ End of Flask Digest, Vol 3, Issue 4 *********************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From krzysztof.sikorski at zerozero.pl Thu Sep 3 15:11:48 2015 From: krzysztof.sikorski at zerozero.pl (Krzysztof Andrzej Sikorski) Date: Thu, 03 Sep 2015 15:11:48 +0200 Subject: [Flask] Flask-Security authentication in JS In-Reply-To: References: Message-ID: On 2015-09-03 08:55, Morgan Connolly wrote: > I didn't know that the browser would transmit cookies even if I used JavaScript, having never worked on a dynamic website before. I just tried adding the JavaScript, and without having to do any other work, it works how I want it to. You were lucky. Cookies can be set with a "httponly" flag, which prevents JavaScript from seeing them. Looks like default Flask configuration does not set that flag. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fededelgado at outlook.com Thu Sep 3 18:28:47 2015 From: fededelgado at outlook.com (Federico Delgado Doyle) Date: Thu, 3 Sep 2015 09:28:47 -0700 Subject: [Flask] Flask-Security authentication in JS In-Reply-To: References: , , , Message-ID: HttpOnly will stop client javascript from messing with the cookie (like getting a copy of it) but it will be transmitted transparently to the server. Same thing for secure cookies, they will be transmitted but only to secure (https) sites. Date: Thu, 3 Sep 2015 15:11:48 +0200 From: krzysztof.sikorski at zerozero.pl To: connollymorg at gmail.com CC: fededelgado at outlook.com; flask at python.org Subject: Re: [Flask] Flask-Security authentication in JS On 2015-09-03 08:55, Morgan Connolly wrote: I didn't know that the browser would transmit cookies even if I used JavaScript, having never worked on a dynamic website before. I just tried adding the JavaScript, and without having to do any other work, it works how I want it to. You were lucky. Cookies can be set with a "httponly" flag, which prevents JavaScript from seeing them. Looks like default Flask configuration does not set that flag. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fededelgado at outlook.com Thu Sep 3 18:36:51 2015 From: fededelgado at outlook.com (Federico Delgado Doyle) Date: Thu, 3 Sep 2015 09:36:51 -0700 Subject: [Flask] Flask-Security authentication in JS In-Reply-To: References: , , , , , , , Message-ID: That means the cookie won't be accesible through document.cookie on javascript. But the roundtrip is still there, no manual intervention required. At least that is how it works for me. From: fededelgado at outlook.com To: krzysztof.sikorski at zerozero.pl; connollymorg at gmail.com Date: Thu, 3 Sep 2015 09:28:47 -0700 Subject: Re: [Flask] Flask-Security authentication in JS CC: flask at python.org HttpOnly will stop client javascript from messing with the cookie (like getting a copy of it) but it will be transmitted transparently to the server. Same thing for secure cookies, they will be transmitted but only to secure (https) sites. Date: Thu, 3 Sep 2015 15:11:48 +0200 From: krzysztof.sikorski at zerozero.pl To: connollymorg at gmail.com CC: fededelgado at outlook.com; flask at python.org Subject: Re: [Flask] Flask-Security authentication in JS On 2015-09-03 08:55, Morgan Connolly wrote: I didn't know that the browser would transmit cookies even if I used JavaScript, having never worked on a dynamic website before. I just tried adding the JavaScript, and without having to do any other work, it works how I want it to. You were lucky. Cookies can be set with a "httponly" flag, which prevents JavaScript from seeing them. Looks like default Flask configuration does not set that flag. _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigernassau at gmail.com Thu Sep 3 19:31:31 2015 From: tigernassau at gmail.com (tigernassau) Date: Thu, 3 Sep 2015 11:31:31 -0600 Subject: [Flask] logging error installing on server In-Reply-To: References: Message-ID: <55E883F3.6030100@gmail.com> flask app is running fine on debian sid dev machine trying to install on server w/ debian jessie and nginx - have simply installed pip install flask and trying to run hello test app getting error Traceback (most recent call last): File "/usr/lib/python2.7/logging/__init__.py", line 859, in emit msg = self.format(record) File "/usr/lib/python2.7/logging/__init__.py", line 732, in format any idea what's causing this and how to fix ? thks -- Tiger Nassau, Inc. www.tigernassau.com From lyc364 at 163.com Fri Sep 4 09:28:10 2015 From: lyc364 at 163.com (lyc364) Date: Fri, 4 Sep 2015 15:28:10 +0800 Subject: [Flask] Having problem in send_file to client Message-ID: <5841acd5.3008.14f97416cae.Coremail.lyc364@163.com> Hi all, I am building a very simple website where there is a download button. By clicking the button, the user could download a specified file from my server. Following is the html file in concern:

and the code in server: @app.route('/download') def give_the_file(): if is_download: file_name = apk_file_path + 'mini1_game_resign.apk' is_download = False return send_file(file_name, as_attachment = True, cache_timeout = 360) The problem is: every time the user click the download button, the browser will trigger a dialog that let the user choose where to save the file. At the moment the dialog appears, the server triggers exceptions: Exception happened during processing of request from ('10.242.4.74', 41403) Traceback (most recent call last): File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock self.process_request(request, client_address) File "C:\Python27\lib\SocketServer.py", line 321, in process_request self.finish_request(request, client_address) File "C:\Python27\lib\SocketServer.py", line 334, in finish_request self.RequestHandlerClass(request, client_address, self) File "C:\Python27\lib\SocketServer.py", line 657, in __init__ self.finish() File "C:\Python27\lib\SocketServer.py", line 716, in finish self.wfile.close() File "C:\Python27\lib\socket.py", line 283, in close self.flush() File "C:\Python27\lib\socket.py", line 307, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 10053] The downloading can go without problem after the user saves the file because the server will receive another /download request. Do you have any ideas on how this happened? Thanks. 2015-09-04 lyc364 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ungern at zetteeh.net Fri Sep 4 11:37:23 2015 From: ungern at zetteeh.net (un gern) Date: Fri, 4 Sep 2015 11:37:23 +0200 Subject: [Flask] content - storing - rendering Message-ID: hi there, somehow i got a bit confused although i thought i did get the basic concept of flask..?! how/ from where does the content (text) get onto the screen? i created a basic.html template and want to work with several child-templates. right now i have stored some information directly in the app.py file and render it on a url-request. but this seems to be the wrong place for the information. i also thought of a little markup-funktion in the app.py file that would take text from an static .txt file stored on the server. or does a database the best job for that - even though i don't need to take/store any user-input? is there any common workflow i missed? thanks! florian -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 842 bytes Desc: Message signed with OpenPGP using GPGMail URL: From ungern at zetteeh.net Fri Sep 4 22:13:12 2015 From: ungern at zetteeh.net (un gern) Date: Fri, 4 Sep 2015 22:13:12 +0200 Subject: [Flask] content - storing - rendering In-Reply-To: References: Message-ID: <1D4CA372-0EDD-4C7A-998A-4326C840BD96@zetteeh.net> hey christophe, thanks for your response. basically i want to do kind of a portfolio-site. the update frequency is maybe once per month. wordpress and other cms-systems - which are probably more common to use in this case - are no option for me. the working-example: the side should host pictures/video/sound related to projects that have a short or semi-long (text-)description. the projects itself should be dynamically rendered - depending on the user-request / a filter. also the text itself should be manipulatable: the side is multi/bi-lingual and each version is available in different versions ('normal' and 'easy language'). right now i have a list of dictionaries like: projects: [{'name': 'skyscraper', 'date': 'may 1999', 'description': 'wow it's really high and looks great'}, {'name': '12 pictures', 'date': 'april 2008', 'description': '12 places of meaningful meaninglessness'},{..}] in the template i'm calling them like {% for project in projects %) blabla {{ project.name }} in {{ project.date }} [? and so on ] {% endfor %} i thought maybe i could have a textfile and write a little markup-python-function that pulls content from that .txt file. if there will be a new project i simply add the description to the textfile. but there is probably a much easier/better solution and i just don't see/get it. basically this is what you do all the time with a blog, right? but i don't need a complete 'online' interface especially because i don't need to take any user input. so far. is it now possible to picture my sorrows? thanks for reading! ( : cheers f On Sep 4, 2015, at 3:36 PM, Christophe Bal wrote: > Hello. > > Can you give a minimal working example ? > > Le 4 sept. 2015 11:37, "un gern" a ?crit : > hi there, > > somehow i got a bit confused although i thought i did get the basic concept of flask..?! > how/ from where does the content (text) get onto the screen? > i created a basic.html template and want to work with several child-templates. right now i have stored some information directly in the app.py file and render it on a url-request. but this seems to be the wrong place for the information. > i also thought of a little markup-funktion in the app.py file that would take text from an static .txt file stored on the server. > or does a database the best job for that - even though i don't need to take/store any user-input? > > is there any common workflow i missed? > > thanks! > florian > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 842 bytes Desc: Message signed with OpenPGP using GPGMail URL: From coreybrett at gmail.com Fri Sep 4 22:39:49 2015 From: coreybrett at gmail.com (Corey Boyle) Date: Fri, 4 Sep 2015 16:39:49 -0400 Subject: [Flask] content - storing - rendering In-Reply-To: <1D4CA372-0EDD-4C7A-998A-4326C840BD96@zetteeh.net> References: <1D4CA372-0EDD-4C7A-998A-4326C840BD96@zetteeh.net> Message-ID: If you don't want to use a database, and you don't want to build an admin portal, then storing the data directly in the code as a dictionary or list seems like a reasonable solution. I would probably create a separate file and import the data into the app file. ~Sent from my Nexus 5 On Sep 4, 2015 4:13 PM, "un gern" wrote: > hey christophe, > > thanks for your response. > basically i want to do kind of a portfolio-site. > the update frequency is maybe once per month. > wordpress and other cms-systems - which are probably more common to use in > this case - are no option for me. > > the working-example: > the side should host pictures/video/sound related to projects that have a > short or semi-long (text-)description. the projects itself should be > dynamically rendered - depending on the user-request / a filter. > also the text itself should be manipulatable: the side is multi/bi-lingual > and each version is available in different versions ('normal' and 'easy > language'). > > right now i have a list of dictionaries like: > projects: [{'name': 'skyscraper', 'date': 'may 1999', 'description': 'wow > it's really high and looks great'}, {'name': '12 pictures', 'date': 'april > 2008', 'description': '12 places of meaningful meaninglessness'},{..}] > > in the template i'm calling them like > > {% for project in projects %) > blabla {{ project.name }} in {{ project.date }} [? and so on ] > {% endfor %} > > > i thought maybe i could have a textfile and write a little > markup-python-function that pulls content from that .txt file. > if there will be a new project i simply add the description to the > textfile. > > but there is probably a much easier/better solution and i just don't > see/get it. > basically this is what you do all the time with a blog, right? but i don't > need a complete 'online' interface especially because i don't need to take > any user input. > > so far. > is it now possible to picture my sorrows? > > thanks for reading! ( : > cheers > f > > On Sep 4, 2015, at 3:36 PM, Christophe Bal wrote: > > > Hello. > > > > Can you give a minimal working example ? > > > > Le 4 sept. 2015 11:37, "un gern" a ?crit : > > hi there, > > > > somehow i got a bit confused although i thought i did get the basic > concept of flask..?! > > how/ from where does the content (text) get onto the screen? > > i created a basic.html template and want to work with several > child-templates. right now i have stored some information directly in the > app.py file and render it on a url-request. but this seems to be the wrong > place for the information. > > i also thought of a little markup-funktion in the app.py file that would > take text from an static .txt file stored on the server. > > or does a database the best job for that - even though i don't need to > take/store any user-input? > > > > is there any common workflow i missed? > > > > thanks! > > florian > > > > > > _______________________________________________ > > 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 fededelgado at outlook.com Sat Sep 5 02:19:25 2015 From: fededelgado at outlook.com (Federico Delgado Doyle) Date: Fri, 4 Sep 2015 17:19:25 -0700 Subject: [Flask] Having problem in send_file to client In-Reply-To: <5841acd5.3008.14f97416cae.Coremail.lyc364@163.com> References: <5841acd5.3008.14f97416cae.Coremail.lyc364@163.com> Message-ID: Hi, >From what I see, the first request is abruptly cancelled by the client (your browser) and the socket server is trying to flush the contents of the response to a socket that is not good anymore. I do not have download code to test if I see the same text. What version of Python are you using? Is your client code calling a page and in the middle of it redirecting to /download or something like that? Date: Fri, 4 Sep 2015 15:28:10 +0800 From: lyc364 at 163.com To: flask at python.org Subject: [Flask] Having problem in send_file to client Hi all, I am building a very simple website where there is a download button. By clicking the button, the user could download a specified file from my server. Following is the html file in concern:

and the code in server: @app.route('/download') def give_the_file(): if is_download: file_name = apk_file_path + 'mini1_game_resign.apk' is_download = False return send_file(file_name, as_attachment = True, cache_timeout = 360) The problem is: every time the user click the download button, the browser will trigger a dialog that let the user choose where to save the file. At the moment the dialog appears, the server triggers exceptions: Exception happened during processing of request from ('10.242.4.74', 41403) Traceback (most recent call last): File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock self.process_request(request, client_address) File "C:\Python27\lib\SocketServer.py", line 321, in process_request self.finish_request(request, client_address) File "C:\Python27\lib\SocketServer.py", line 334, in finish_request self.RequestHandlerClass(request, client_address, self) File "C:\Python27\lib\SocketServer.py", line 657, in __init__ self.finish() File "C:\Python27\lib\SocketServer.py", line 716, in finish self.wfile.close() File "C:\Python27\lib\socket.py", line 283, in close self.flush() File "C:\Python27\lib\socket.py", line 307, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 10053] The downloading can go without problem after the user saves the file because the server will receive another /download request. Do you have any ideas on how this happened? Thanks. 2015-09-04 lyc364 _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigernassau at gmail.com Sun Sep 6 06:22:47 2015 From: tigernassau at gmail.com (tigernassau) Date: Sat, 5 Sep 2015 22:22:47 -0600 Subject: [Flask] serious problems with deploying flask app to server Message-ID: <55EBBF97.3060307@gmail.com> Not sure whether it's an issue with docs or even a bug in wsgi - what should be a 30 minute task is turning into 3 days! Although deploying the simple flask hello world example to a standard server should be a really basic task, good step by step docs are really lacking - we couldn't find a single specific working example and many other people reporting trouble on stackoverflow are dissed without solutions. The pocoo.org docs do not show a working complete example - this is making using Flask really difficult to use compared to other frameworks. Can we turn this example into some good step by step docs. we first tried nginx w/ uwsgi but this failed big time - somehow nginx is caching the non-working nginx.conf with uwsgi and couldn't clear it or even reset the server - so purged nginx and moved to Apache while apache is working fine for serving several other static sites with virtual hosts, the following flask app is failing on Apache - it's also caching some process so even after removing the app conf file in sites-enabled, we cannot restart the server - apparently some process is running that we cannot find or kill and requiring the whole server to come down. something is seriously wrong here - not sure what the hell wsgi is doing. ourproject.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return '

Hello

' if __name__ == "__main__": app.run(debug=True, host='127.0.0.1',port='8040') ourproject.wsgi # wsgi file import os, sys sys.path.insert(0,"var/www/ourproject") from ourproject import app as application # ourproject.conf ServerName ourproject.com ServerAlias www.ourproject.com DocumentRoot /var/www/ourproject/ ErrorLog /var/www/ourproject/logs/error.log CustomLog /var/www/ourproject/logs/access.log combined WSGIDaemonProcess ourproject user=www-data group=www-data threads=5 WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi WSGIProcessGroup ourproject WSGIApplicationGroup %{GLOBAL} Order allow, deny Allow from all Alias /static /var/www/ourproject/static ** not sure what %{GLOBAL} should be 1,1 Top -- Tiger Nassau, Inc. www.tigernassau.com From jicenhower at yahoo.com Sun Sep 6 23:07:45 2015 From: jicenhower at yahoo.com (Jim Icenhower) Date: Sun, 6 Sep 2015 21:07:45 +0000 (UTC) Subject: [Flask] How to drop one table using Flask and SQLAlchemy Message-ID: <292807147.2356464.1441573665129.JavaMail.yahoo@mail.yahoo.com> Hi,I'm using Flask appbuilder with SQLAlchemy. I would like to be able to drop one table instead of using drop_all(). I've attempted to use a bind to the table but I obviously don't understand what I'm doing. I've done this: In models.py: class CarClass(Model):? ? CarClassID = Column(Integer, primary_key=True)? ? EventID = Column(Integer, ForeignKey('event.EventID'), nullable=False)? ? EventKey = Column(String(30), nullable=False)? ? CarClassKey = Column(String(30), nullable=False)? ? Description = Column(Text(1000), unique=True, nullable=False)? ? Abbreviation = Column(String(10), unique=True, nullable=False)? ? Event = relationship('Event')? ? __bind_key__ = 'carclass' In views.py:db.drop_all(bind=['carclass']) This returns the error:AssertionError: Bind 'carclass' is not specified. Set it in the SQLALCHEMY_BINDS configuration variable. Maybe I should not use binds. I just want to drop a table that is described by a class in models.py. Is there a better way than binds to drop one table? Thanks! ?Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From arsh840 at gmail.com Tue Sep 8 08:33:39 2015 From: arsh840 at gmail.com (Great Avenger Singh) Date: Tue, 8 Sep 2015 12:03:39 +0530 Subject: [Flask] Save Matplot file in svg format Message-ID: Hi, I am using matplotlib to generate graph and save them as a SVG format. A simple Python program like following does required work. import matplotlib.pyplot as plt import numpy as np plt.figure(figsize=[6,6]) x = np.arange(0,100,0.00001) y = x*np.sin(2*pi*x) plt.plot(y) plt.axis('off') plt.gca().set_position([0, 0, 1, 1]) plt.savefig("test.svg") But this is not working with Flask. I want to save file in fileSystem. -- Thanks Arshpreet Singh I am Sikh boy, Learning by doing and Learning by teaching is my religion. ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/ From scott.werner.vt at gmail.com Tue Sep 8 14:15:18 2015 From: scott.werner.vt at gmail.com (Scott Werner) Date: Tue, 8 Sep 2015 08:15:18 -0400 Subject: [Flask] Save Matplot file in svg format In-Reply-To: References: Message-ID: Next time provide your flask code that is not working. Here's an example of returning a matplotlib graph as SVG format: https://gist.github.com/wilsaj/862153. Since you want to save it to the fileSystem, you will need to implement two routes, see http://stackoverflow.com/questions/20107414/passing-a-matplotlib-figure-to-html-flask . On Tue, Sep 8, 2015 at 2:33 AM, Great Avenger Singh wrote: > Hi, > > I am using matplotlib to generate graph and save them as a SVG format. > A simple Python program like following does required work. > > > > import matplotlib.pyplot as plt > import numpy as np > > plt.figure(figsize=[6,6]) > x = np.arange(0,100,0.00001) > y = x*np.sin(2*pi*x) > plt.plot(y) > plt.axis('off') > plt.gca().set_position([0, 0, 1, 1]) > plt.savefig("test.svg") > > > > But this is not working with Flask. I want to save file in fileSystem. > > -- > > Thanks > Arshpreet Singh > > I am Sikh boy, Learning by doing and Learning by teaching is my religion. > > ------------------------------------------------------------------------------ > Slashdot TV. > Video for Nerds. Stuff that matters. > http://tv.slashdot.org/ > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -- Scott Werner scott.werner.vt at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at gushee.net Tue Sep 8 19:56:49 2015 From: matt at gushee.net (Matt Gushee) Date: Tue, 8 Sep 2015 11:56:49 -0600 Subject: [Flask] serious problems with deploying flask app to server In-Reply-To: <55EBBF97.3060307@gmail.com> References: <55EBBF97.3060307@gmail.com> Message-ID: Hi, Tiger-- I used to run a Flask site with nginx & uwsgi; I can't recall any major issues with deployment. That site is not currently up, but I'll see if I can find the configs. Meanwhile, this is just to let you know that it *should* work. IMHO. -- Matt Gushee On Sat, Sep 5, 2015 at 10:22 PM, tigernassau wrote: > Not sure whether it's an issue with docs or even a bug in wsgi - what > should be a 30 minute task is turning into 3 days! > > Although deploying the simple flask hello world example to a standard > server should be a really basic task, good step by step docs are really > lacking - we couldn't find a single specific working example and many other > people reporting trouble on stackoverflow are dissed without solutions. > The pocoo.org docs do not show a working complete example - this is > making using Flask really difficult to use compared to other frameworks. > Can we turn this example into some good step by step docs. > > we first tried nginx w/ uwsgi but this failed big time - somehow nginx is > caching the non-working nginx.conf with uwsgi and couldn't clear it or even > reset the server - so purged nginx and moved to Apache > > while apache is working fine for serving several other static sites with > virtual hosts, the following flask app is failing on Apache - it's also > caching some process so even after removing the app conf file in > sites-enabled, we cannot restart the server - apparently some process is > running that we cannot find or kill and requiring the whole server to come > down. something is seriously wrong here - not sure what the hell wsgi is > doing. > > ourproject.py > from flask import Flask > app = Flask(__name__) > @app.route('/') > def hello(): > return '

Hello

' > if __name__ == "__main__": > app.run(debug=True, host='127.0.0.1',port='8040') > > ourproject.wsgi > # wsgi file > import os, sys > sys.path.insert(0,"var/www/ourproject") > from ourproject import app as application > > > # ourproject.conf > > ServerName ourproject.com > ServerAlias www.ourproject.com > DocumentRoot /var/www/ourproject/ > ErrorLog /var/www/ourproject/logs/error.log > CustomLog /var/www/ourproject/logs/access.log combined > > WSGIDaemonProcess ourproject user=www-data group=www-data threads=5 > WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi > > > WSGIProcessGroup ourproject > WSGIApplicationGroup %{GLOBAL} > Order allow, deny > Allow from all > > > Alias /static /var/www/ourproject/static > > > ** not sure what %{GLOBAL} should be > > 1,1 Top > > > > -- > Tiger Nassau, Inc. > www.tigernassau.com > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tigernassau at gmail.com Tue Sep 8 21:30:34 2015 From: tigernassau at gmail.com (tigernassau) Date: Tue, 8 Sep 2015 13:30:34 -0600 Subject: [Flask] serious problems with deploying flask app to server In-Reply-To: References: <55EBBF97.3060307@gmail.com> Message-ID: <55EF375A.6030703@gmail.com> On 09/08/2015 11:56 AM, Matt Gushee wrote: > Hi, Tiger-- > > I used to run a Flask site with nginx & uwsgi; I can't recall any > major issues with deployment. That site is not currently up, but I'll > see if I can find the configs. Meanwhile, this is just to let you know > that it *should* work. IMHO. hope you can post a working solution - we made progress by also looking at Bottle docs and now don't have server errors but Flask app domain is reverting to the Apache page and not running the flask app - that would indicated a virtual host issue but a static html page shows up fine on this domain - maybe a port issue ?? - maybe the Flask app not running ?? maybe version conflicts (used latest Deb 8 for python (2.7x) , mod-wsgi and pip install Flask). After 4 days, have run out of ideas to try. I realize there are variables (Apache vs Nginx, Debian vs Ubuntu vs RedHat, standalone vs virtual hosts) but should be easy enough to have working examples of these most typical deployments) Flask was really great for developing our site - now if we can only get it deployed (: > > -- > Matt Gushee > > On Sat, Sep 5, 2015 at 10:22 PM, tigernassau > wrote: > > Not sure whether it's an issue with docs or even a bug in wsgi - > what should be a 30 minute task is turning into 3 days! > > Although deploying the simple flask hello world example to a > standard server should be a really basic task, good step by step > docs are really lacking - we couldn't find a single specific > working example and many other people reporting trouble on > stackoverflow are dissed without solutions. The pocoo.org > docs do not show a working complete example - > this is making using Flask really difficult to use compared to > other frameworks. Can we turn this example into some good step by > step docs. > > we first tried nginx w/ uwsgi but this failed big time - somehow > nginx is caching the non-working nginx.conf with uwsgi and > couldn't clear it or even reset the server - so purged nginx and > moved to Apache > > while apache is working fine for serving several other static > sites with virtual hosts, the following flask app is failing on > Apache - it's also caching some process so even after removing the > app conf file in sites-enabled, we cannot restart the server - > apparently some process is running that we cannot find or kill and > requiring the whole server to come down. something is seriously > wrong here - not sure what the hell wsgi is doing. > > ourproject.py > from flask import Flask > app = Flask(__name__) > @app.route('/') > def hello(): > return '

Hello

' > if __name__ == "__main__": > app.run(debug=True, host='127.0.0.1',port='8040') > > ourproject.wsgi > # wsgi file > import os, sys > sys.path.insert(0,"var/www/ourproject") > from ourproject import app as application > > > # ourproject.conf > > ServerName ourproject.com > ServerAlias www.ourproject.com > DocumentRoot /var/www/ourproject/ > ErrorLog /var/www/ourproject/logs/error.log > CustomLog /var/www/ourproject/logs/access.log combined > > WSGIDaemonProcess ourproject user=www-data group=www-data threads=5 > WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi > > > WSGIProcessGroup ourproject > WSGIApplicationGroup %{GLOBAL} > Order allow, deny > Allow from all > > > Alias /static /var/www/ourproject/static > > > ** not sure what %{GLOBAL} should be > > 1,1 Top > > > > -- > Tiger Nassau, Inc. > www.tigernassau.com > > _______________________________________________ > 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 -- Tiger Nassau, Inc. www.tigernassau.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at bizzartech.com Tue Sep 8 21:53:51 2015 From: brad at bizzartech.com (Brad Derstine) Date: Tue, 8 Sep 2015 15:53:51 -0400 Subject: [Flask] serious problems with deploying flask app to server In-Reply-To: <55EF375A.6030703@gmail.com> References: <55EBBF97.3060307@gmail.com> <55EF375A.6030703@gmail.com> Message-ID: <2E07F458-36B7-4034-934A-3E97C3ACA039@bizzartech.com> I?ve been creating some cookie cutter cms installs of flask with Apache 2.4 and mod_wsgi and running multiple other sites on a server using virtual environments and virtualhosts. So far so good! Below is what?s currently working for me? I?m happy to explain anything I?m using. You can view the full repo with setup.sh script for how I?m deploying it at https://github.com/bderstine/WebsiteMixer-App-Base I installed to /srv/websitemixer.com/ and here are the files I used? YMMV I?m using Ubuntu 14.04 and whatever Python 2.7 the official repos think is current. /srv/websitemixer.com/api.wsgi ================ #!/bin/python activate_this = '/srv/websitemixer.com/venv/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) import sys sys.path.append('/srv/websitemixer.com') from application import app as application ================ /etc/apache2/sites-enabled/websitemixer.com .conf ================ ServerName websitemixer.com ServerAlias www.websitemixer.com DocumentRoot /var/www WSGIDaemonProcess apiwebsitemixer user=www-data group=www-data threads=5 WSGIScriptAlias / /srv/websitemixer.com/api.wsgi WSGIPassAuthorization On Order deny,allow Allow from all WSGIProcessGroup apiwebsitemixer WSGIApplicationGroup %{GLOBAL} WSGIScriptReloading On Order deny,allow Allow from all ExpiresActive On #ExpiresByType text/css "now plus 7 days" ExpiresDefault "access plus 1 month" Header set Cache-Control "max-age=1296000, public" Require all granted LogLevel warn CustomLog ${APACHE_LOG_DIR}/websitemixer.com-access.log combined ErrorLog ${APACHE_LOG_DIR}/websitemixer.com-error.log ================ > On Sep 8, 2015, at 3:30 PM, tigernassau wrote: > > On 09/08/2015 11:56 AM, Matt Gushee wrote: >> Hi, Tiger-- >> >> I used to run a Flask site with nginx & uwsgi; I can't recall any major issues with deployment. That site is not currently up, but I'll see if I can find the configs. Meanwhile, this is just to let you know that it *should* work. IMHO. > > hope you can post a working solution - we made progress by also looking at Bottle docs and now don't have server errors but Flask app domain is reverting to the Apache page and not running the flask app - that would indicated a virtual host issue but a static html page shows up fine on this domain - maybe a port issue ?? - maybe the Flask app not running ?? maybe version conflicts (used latest Deb 8 for python (2.7x) , mod-wsgi and pip install Flask). After 4 days, have run out of ideas to try. > > I realize there are variables (Apache vs Nginx, Debian vs Ubuntu vs RedHat, standalone vs virtual hosts) but should be easy enough to have working examples of these most typical deployments) > > Flask was really great for developing our site - now if we can only get it deployed (: > > >> >> -- >> Matt Gushee >> >> On Sat, Sep 5, 2015 at 10:22 PM, tigernassau > wrote: >> Not sure whether it's an issue with docs or even a bug in wsgi - what should be a 30 minute task is turning into 3 days! >> >> Although deploying the simple flask hello world example to a standard server should be a really basic task, good step by step docs are really lacking - we couldn't find a single specific working example and many other people reporting trouble on stackoverflow are dissed without solutions. The pocoo.org docs do not show a working complete example - this is making using Flask really difficult to use compared to other frameworks. Can we turn this example into some good step by step docs. >> >> we first tried nginx w/ uwsgi but this failed big time - somehow nginx is caching the non-working nginx.conf with uwsgi and couldn't clear it or even reset the server - so purged nginx and moved to Apache >> >> while apache is working fine for serving several other static sites with virtual hosts, the following flask app is failing on Apache - it's also caching some process so even after removing the app conf file in sites-enabled, we cannot restart the server - apparently some process is running that we cannot find or kill and requiring the whole server to come down. something is seriously wrong here - not sure what the hell wsgi is doing. >> >> ourproject.py >> from flask import Flask >> app = Flask(__name__) >> @app.route('/') >> def hello(): >> return '

Hello

' >> if __name__ == "__main__": >> app.run(debug=True, host='127.0.0.1',port='8040') >> >> ourproject.wsgi >> # wsgi file >> import os, sys >> sys.path.insert(0,"var/www/ourproject") >> from ourproject import app as application >> >> >> # ourproject.conf >> >> ServerName ourproject.com >> ServerAlias www.ourproject.com >> DocumentRoot /var/www/ourproject/ >> ErrorLog /var/www/ourproject/logs/error.log >> CustomLog /var/www/ourproject/logs/access.log combined >> >> WSGIDaemonProcess ourproject user=www-data group=www-data threads=5 >> WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi >> >> >> WSGIProcessGroup ourproject >> WSGIApplicationGroup %{GLOBAL} >> Order allow, deny >> Allow from all >> >> >> Alias /static /var/www/ourproject/static >> >> >> ** not sure what %{GLOBAL} should be >> >> 1,1 Top >> >> >> >> -- >> Tiger Nassau, Inc. >> www.tigernassau.com >> >> _______________________________________________ >> 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 > > > -- > Tiger Nassau, Inc. > www.tigernassau.com _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at bizzartech.com Wed Sep 9 15:18:18 2015 From: brad at bizzartech.com (Brad Derstine) Date: Wed, 9 Sep 2015 09:18:18 -0400 Subject: [Flask] serious problems with deploying flask app to server In-Reply-To: <55EF5A9D.9060701@gmail.com> References: <55EBBF97.3060307@gmail.com> <55EF375A.6030703@gmail.com> <2E07F458-36B7-4034-934A-3E97C3ACA039@bizzartech.com> <55EF5A9D.9060701@gmail.com> Message-ID: <030901d0eb01$fe8702e0$fb9508a0$@bizzartech.com> For your questions, 1. The virtualhost entry uses the wsgi mod to spin up a subprocess that serves the http request, no port is required since wsgi handles that. 2. I think your wsgi file is still wrong. That "from application import app as application" line is specific to the file structure of websitemixer, it will need to be adjusted for your environment. Try this instead. ##### /var/www/ourproject/ourproject.wsgi import sys sys.path.append("/var/www/ourproject/") from ourproject import app Remember to restart apache any time you make changes too since it isn't loading files dynamically like the built in python web server does. Keep an eye on the error_log of apache too, it may point at any issues not easily seen since your using Apache and not the dev server. -Brad From: tigernassau [mailto:tigernassau at gmail.com] Sent: Tuesday, September 8, 2015 6:01 PM To: Brad Derstine Cc: Matt Gushee ; flask at python.org Subject: Re: [Flask] serious problems with deploying flask app to server thks for info - ours is only different in that we are not running in virtualenv (so don't have the activate code ) and not using ssl (later on our task list) still getting apache page - here is our test setup: questions: 1) we understand apache virtual find by name but how does it know what port Flask would run on ?? 2) without virtualenv do we still need to activate flask somehow ?? #### /var/www/ourproject/ourproject.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return '

Hello

' # # if __name__ == "__main__": # app.run(debug=True) ##### /var/www/ourproject/ourproject.wsgi # wsgi file import sys sys.path.append("var/www/ourproject") # import os # os.chdir("/var/www/ourproject") from application import app as application ###### /etc/apache2/sites-enabled/ourproject.conf ServerName ourproject.com ServerAlias www.ourproject.com DocumentRoot /var/www/ourproject/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined WSGIDaemonProcess ourproject user=www-data group=www-data processes=2 threads=5 WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi WSGIPassAuthorization On WSGIProcessGroup ourproject WSGIApplicationGroup %{GLOBAL} Require all granted On 09/08/2015 01:53 PM, Brad Derstine wrote: I've been creating some cookie cutter cms installs of flask with Apache 2.4 and mod_wsgi and running multiple other sites on a server using virtual environments and virtualhosts. So far so good! Below is what's currently working for me. I'm happy to explain anything I'm using. You can view the full repo with setup.sh script for how I'm deploying it at https://github.com/bderstine/WebsiteMixer-App-Base I installed to /srv/websitemixer.com/ and here are the files I used. YMMV I'm using Ubuntu 14.04 and whatever Python 2.7 the official repos think is current. /srv/websitemixer.com/api.wsgi ================ #!/bin/python activate_this = '/srv/websitemixer.com/venv/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) import sys sys.path.append('/srv/websitemixer.com ') from application import app as application ================ /etc/apache2/sites-enabled/websitemixer.com.conf ================ ServerName websitemixer.com ServerAlias www.websitemixer.com DocumentRoot /var/www WSGIDaemonProcess apiwebsitemixer user=www-data group=www-data threads=5 WSGIScriptAlias / /srv/websitemixer.com/api.wsgi WSGIPassAuthorization On Order deny,allow Allow from all > WSGIProcessGroup apiwebsitemixer WSGIApplicationGroup %{GLOBAL} WSGIScriptReloading On Order deny,allow Allow from all ExpiresActive On #ExpiresByType text/css "now plus 7 days" ExpiresDefault "access plus 1 month" Header set Cache-Control "max-age=1296000, public" Require all granted LogLevel warn CustomLog ${APACHE_LOG_DIR}/websitemixer.com -access.log combined ErrorLog ${APACHE_LOG_DIR}/websitemixer.com -error.log ================ On Sep 8, 2015, at 3:30 PM, tigernassau > wrote: On 09/08/2015 11:56 AM, Matt Gushee wrote: Hi, Tiger-- I used to run a Flask site with nginx & uwsgi; I can't recall any major issues with deployment. That site is not currently up, but I'll see if I can find the configs. Meanwhile, this is just to let you know that it *should* work. IMHO. hope you can post a working solution - we made progress by also looking at Bottle docs and now don't have server errors but Flask app domain is reverting to the Apache page and not running the flask app - that would indicated a virtual host issue but a static html page shows up fine on this domain - maybe a port issue ?? - maybe the Flask app not running ?? maybe version conflicts (used latest Deb 8 for python (2.7x) , mod-wsgi and pip install Flask). After 4 days, have run out of ideas to try. I realize there are variables (Apache vs Nginx, Debian vs Ubuntu vs RedHat, standalone vs virtual hosts) but should be easy enough to have working examples of these most typical deployments) Flask was really great for developing our site - now if we can only get it deployed (: -- Matt Gushee On Sat, Sep 5, 2015 at 10:22 PM, tigernassau > wrote: Not sure whether it's an issue with docs or even a bug in wsgi - what should be a 30 minute task is turning into 3 days! Although deploying the simple flask hello world example to a standard server should be a really basic task, good step by step docs are really lacking - we couldn't find a single specific working example and many other people reporting trouble on stackoverflow are dissed without solutions. The pocoo.org docs do not show a working complete example - this is making using Flask really difficult to use compared to other frameworks. Can we turn this example into some good step by step docs. we first tried nginx w/ uwsgi but this failed big time - somehow nginx is caching the non-working nginx.conf with uwsgi and couldn't clear it or even reset the server - so purged nginx and moved to Apache while apache is working fine for serving several other static sites with virtual hosts, the following flask app is failing on Apache - it's also caching some process so even after removing the app conf file in sites-enabled, we cannot restart the server - apparently some process is running that we cannot find or kill and requiring the whole server to come down. something is seriously wrong here - not sure what the hell wsgi is doing. ourproject.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return '

Hello

' if __name__ == "__main__": app.run(debug=True, host='127.0.0.1',port='8040') ourproject.wsgi # wsgi file import os, sys sys.path.insert(0,"var/www/ourproject") from ourproject import app as application # ourproject.conf ServerName ourproject.com ServerAlias www.ourproject.com DocumentRoot /var/www/ourproject/ ErrorLog /var/www/ourproject/logs/error.log CustomLog /var/www/ourproject/logs/access.log combined WSGIDaemonProcess ourproject user=www-data group=www-data threads=5 WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi WSGIProcessGroup ourproject WSGIApplicationGroup %{GLOBAL} Order allow, deny Allow from all Alias /static /var/www/ourproject/static ** not sure what %{GLOBAL} should be 1,1 Top -- Tiger Nassau, Inc. www.tigernassau.com _______________________________________________ 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 -- Tiger Nassau, Inc. www.tigernassau.com _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -- Tiger Nassau, Inc. www.tigernassau.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From brad at bizzartech.com Wed Sep 9 16:12:04 2015 From: brad at bizzartech.com (Brad Derstine) Date: Wed, 9 Sep 2015 10:12:04 -0400 Subject: [Flask] serious problems with deploying flask app to server In-Reply-To: <55EF5A9D.9060701@gmail.com> References: <55EBBF97.3060307@gmail.com> <55EF375A.6030703@gmail.com> <2E07F458-36B7-4034-934A-3E97C3ACA039@bizzartech.com> <55EF5A9D.9060701@gmail.com> Message-ID: <033c01d0eb09$81720270$84560750$@bizzartech.com> I found the issue with the default apache page. your VirtualHost tag has to be *:80 () And /var/www/ourproject/ourproject.wsgi should look like this (the wsgi expects an "application" model) ############ import sys sys.path.append("/var/www/ourproject/") from ourproject import app as application I tried this on a test server and worked for me. -Brad From: tigernassau [mailto:tigernassau at gmail.com] Sent: Tuesday, September 8, 2015 6:01 PM To: Brad Derstine Cc: Matt Gushee ; flask at python.org Subject: Re: [Flask] serious problems with deploying flask app to server thks for info - ours is only different in that we are not running in virtualenv (so don't have the activate code ) and not using ssl (later on our task list) still getting apache page - here is our test setup: questions: 1) we understand apache virtual find by name but how does it know what port Flask would run on ?? 2) without virtualenv do we still need to activate flask somehow ?? #### /var/www/ourproject/ourproject.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return '

Hello

' # # if __name__ == "__main__": # app.run(debug=True) ##### /var/www/ourproject/ourproject.wsgi # wsgi file import sys sys.path.append("var/www/ourproject") # import os # os.chdir("/var/www/ourproject") from application import app as application ###### /etc/apache2/sites-enabled/ourproject.conf ServerName ourproject.com ServerAlias www.ourproject.com DocumentRoot /var/www/ourproject/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined WSGIDaemonProcess ourproject user=www-data group=www-data processes=2 threads=5 WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi WSGIPassAuthorization On WSGIProcessGroup ourproject WSGIApplicationGroup %{GLOBAL} Require all granted On 09/08/2015 01:53 PM, Brad Derstine wrote: I've been creating some cookie cutter cms installs of flask with Apache 2.4 and mod_wsgi and running multiple other sites on a server using virtual environments and virtualhosts. So far so good! Below is what's currently working for me. I'm happy to explain anything I'm using. You can view the full repo with setup.sh script for how I'm deploying it at https://github.com/bderstine/WebsiteMixer-App-Base I installed to /srv/websitemixer.com/ and here are the files I used. YMMV I'm using Ubuntu 14.04 and whatever Python 2.7 the official repos think is current. /srv/websitemixer.com/api.wsgi ================ #!/bin/python activate_this = '/srv/websitemixer.com/venv/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) import sys sys.path.append('/srv/websitemixer.com ') from application import app as application ================ /etc/apache2/sites-enabled/websitemixer.com .conf ================ ServerName websitemixer.com ServerAlias www.websitemixer.com DocumentRoot /var/www WSGIDaemonProcess apiwebsitemixer user=www-data group=www-data threads=5 WSGIScriptAlias / /srv/websitemixer.com/api.wsgi WSGIPassAuthorization On Order deny,allow Allow from all > WSGIProcessGroup apiwebsitemixer WSGIApplicationGroup %{GLOBAL} WSGIScriptReloading On Order deny,allow Allow from all ExpiresActive On #ExpiresByType text/css "now plus 7 days" ExpiresDefault "access plus 1 month" Header set Cache-Control "max-age=1296000, public" Require all granted LogLevel warn CustomLog ${APACHE_LOG_DIR}/websitemixer.com -access.log combined ErrorLog ${APACHE_LOG_DIR}/websitemixer.com -error.log ================ On Sep 8, 2015, at 3:30 PM, tigernassau > wrote: On 09/08/2015 11:56 AM, Matt Gushee wrote: Hi, Tiger-- I used to run a Flask site with nginx & uwsgi; I can't recall any major issues with deployment. That site is not currently up, but I'll see if I can find the configs. Meanwhile, this is just to let you know that it *should* work. IMHO. hope you can post a working solution - we made progress by also looking at Bottle docs and now don't have server errors but Flask app domain is reverting to the Apache page and not running the flask app - that would indicated a virtual host issue but a static html page shows up fine on this domain - maybe a port issue ?? - maybe the Flask app not running ?? maybe version conflicts (used latest Deb 8 for python (2.7x) , mod-wsgi and pip install Flask). After 4 days, have run out of ideas to try. I realize there are variables (Apache vs Nginx, Debian vs Ubuntu vs RedHat, standalone vs virtual hosts) but should be easy enough to have working examples of these most typical deployments) Flask was really great for developing our site - now if we can only get it deployed (: -- Matt Gushee On Sat, Sep 5, 2015 at 10:22 PM, tigernassau > wrote: Not sure whether it's an issue with docs or even a bug in wsgi - what should be a 30 minute task is turning into 3 days! Although deploying the simple flask hello world example to a standard server should be a really basic task, good step by step docs are really lacking - we couldn't find a single specific working example and many other people reporting trouble on stackoverflow are dissed without solutions. The pocoo.org docs do not show a working complete example - this is making using Flask really difficult to use compared to other frameworks. Can we turn this example into some good step by step docs. we first tried nginx w/ uwsgi but this failed big time - somehow nginx is caching the non-working nginx.conf with uwsgi and couldn't clear it or even reset the server - so purged nginx and moved to Apache while apache is working fine for serving several other static sites with virtual hosts, the following flask app is failing on Apache - it's also caching some process so even after removing the app conf file in sites-enabled, we cannot restart the server - apparently some process is running that we cannot find or kill and requiring the whole server to come down. something is seriously wrong here - not sure what the hell wsgi is doing. ourproject.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return '

Hello

' if __name__ == "__main__": app.run(debug=True, host='127.0.0.1',port='8040') ourproject.wsgi # wsgi file import os, sys sys.path.insert(0,"var/www/ourproject") from ourproject import app as application # ourproject.conf ServerName ourproject.com ServerAlias www.ourproject.com DocumentRoot /var/www/ourproject/ ErrorLog /var/www/ourproject/logs/error.log CustomLog /var/www/ourproject/logs/access.log combined WSGIDaemonProcess ourproject user=www-data group=www-data threads=5 WSGIScriptAlias / /var/www/ourproject/ourproject.wsgi WSGIProcessGroup ourproject WSGIApplicationGroup %{GLOBAL} Order allow, deny Allow from all Alias /static /var/www/ourproject/static ** not sure what %{GLOBAL} should be 1,1 Top -- Tiger Nassau, Inc. www.tigernassau.com _______________________________________________ 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 -- Tiger Nassau, Inc. www.tigernassau.com _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -- Tiger Nassau, Inc. www.tigernassau.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Thu Sep 10 20:16:35 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Thu, 10 Sep 2015 14:16:35 -0400 Subject: [Flask] Multiple forms linked to a single submit button Message-ID: Hi all, I am very new to Flask and web development. I have been working through the Flask book by Grinberg. I am having trouble with the following sort of thing. I would like to have multiple string fields triggered by the same submit button. I would like to have all of the string fields as required. Here is my Flask script: from flask import Flask from flask import render_template, request from flask_wtf import Form from wtforms import StringField from wtforms.validators import Required app = Flask(__name__) app.config['SECRET_KEY'] = 'string' class MyForm(Form): name = StringField('name', validators=[Required()]) @app.route('/',methods=['GET','POST']) def index(): name1 = None form1 = MyForm(prefix='form1') name2 = None form2 = MyForm(prefix='form2') print request if form1.validate_on_submit(): name1 = form1.name.data print name1 form1.name.data = "" elif form2.validate_on_submit(): name2 = form2.name.data print name2 form2.name.data="" return render_template('index.html', form1=form1, form2=form2) if __name__=='__main__': app.run(host='0.0.0.0',debug=True) Here is my templates/index.html:
{{ form1.csrf_token }} {{ form1.name.label }} {{ form1.name(size=20) }}
{{ form2.csrf_token }} {{ form2.name.label }} {{ form2.name(size=20) }}
Right now I have two buttons that do not properly submit data for each field, that is answered here though . Again, I would like to have a single input button that links to both required string fields. Here is pseudocode of how I see it happening :
{{ form1.csrf_token }} {{ form1.name.label }} {{ form1.name(size=20) }}
{{ form2.csrf_token }} {{ form2.name.label }} {{ form2.name(size=20) }}
, where input-id="trigger" links the forms to the submit button. I suppose this is more of an html question as written, but perhaps there is a better way to do this in the Flask-WTForms framework. Thanks, Kyle -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Thu Sep 10 20:55:29 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Thu, 10 Sep 2015 14:55:29 -0400 Subject: [Flask] Multiple forms linked to a single submit button In-Reply-To: References: Message-ID: Here is a change to the view function that makes the two string fields with two submit buttons work individually. def index(): name1 = None form1 = MyForm(prefix='form1') name2 = None form2 = MyForm(prefix='form2') if form1.validate_on_submit() and request.form['btn']=='form1': name1 = form1.name.data print form1.name, name1 form1.name.data = '' elif form2.validate_on_submit() and request.form['btn']=='form2': name2 = form2.name.data print form2.name, name2 form2.name.data='' return render_template('index.html', form1=form1, form2=form2) Not that this answers the question, but I think for completeness why not add it to the email chain. Perhaps it is incorrect anyway. In which case please feel free to correct me. On Thu, Sep 10, 2015 at 2:16 PM, Kyle Lawlor wrote: > Hi all, > > I am very new to Flask and web development. I have been working through > the Flask book by Grinberg. I am having trouble with the following sort of > thing. I would like to have multiple string fields triggered by the same > submit button. I would like to have all of the string fields as required. > > Here is my Flask script: > > from flask import Flask > from flask import render_template, request > from flask_wtf import Form > from wtforms import StringField > from wtforms.validators import Required > > app = Flask(__name__) > app.config['SECRET_KEY'] = 'string' > > class MyForm(Form): > name = StringField('name', validators=[Required()]) > > @app.route('/',methods=['GET','POST']) > def index(): > name1 = None > form1 = MyForm(prefix='form1') > name2 = None > form2 = MyForm(prefix='form2') > print request > if form1.validate_on_submit(): > name1 = form1.name.data > print name1 > form1.name.data = "" > elif form2.validate_on_submit(): > name2 = form2.name.data > print name2 > form2.name.data="" > return render_template('index.html', > form1=form1, > form2=form2) > > if __name__=='__main__': > app.run(host='0.0.0.0',debug=True) > > Here is my templates/index.html: > > >
> {{ form1.csrf_token }} > {{ form1.name.label }} {{ form1.name(size=20) }} > >
>
> {{ form2.csrf_token }} > {{ form2.name.label }} {{ form2.name(size=20) }} > >
> > > Right now I have two buttons that do not properly submit data for each > field, that is answered here though > . > Again, I would like to have a single input button that links to both > required string fields. > > Here is pseudocode of how I see it happening : > > >
> {{ form1.csrf_token }} > {{ form1.name.label }} {{ form1.name(size=20) }} >
>
> {{ form2.csrf_token }} > {{ form2.name.label }} {{ form2.name(size=20) }} >
> > > > , where input-id="trigger" links the forms to the submit button. > > I suppose this is more of an html question as written, but perhaps there > is a better way to do this in the Flask-WTForms framework. > > Thanks, > Kyle > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattshields.org Mon Sep 14 14:46:46 2015 From: matt at mattshields.org (Matt Shields) Date: Mon, 14 Sep 2015 08:46:46 -0400 Subject: [Flask] Expiring login sessions Message-ID: Below is what I had put in when I was building the login and sessions. I've tried setting the app.permanent_session_lifetime to a specific amount of time so that the user will get logged out and it doesn't seem to work. Also, besides logging them out after a specific amount of time, I'd like to have them logged out if they close their browser 29 @app.before_request 30 def before_request(): 31 g.permission = config.permission_problem() 32 g.current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 33 session.permanent = True 34 app.permanent_session_lifetime = datetime.timedelta(minutes=60) 35 36 if current_user.is_authenticated(): 37 user = User.query.filter_by(email=current_user.email).first() 38 user.current_login_at = datetime.datetime.now() 39 db.session.commit() Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: From liminglangjun at gmail.com Tue Sep 15 02:59:03 2015 From: liminglangjun at gmail.com (Minglangjun Li) Date: Tue, 15 Sep 2015 00:59:03 +0000 Subject: [Flask] Expiring login sessions In-Reply-To: References: Message-ID: Have you tried to set it in a config file? On Mon, Sep 14, 2015 at 12:46 PM, Matt Shields wrote: > Below is what I had put in when I was building the login and sessions. > I've tried setting the app.permanent_session_lifetime to a specific amount > of time so that the user will get logged out and it doesn't seem to work. > Also, besides logging them out after a specific amount of time, I'd like to > have them logged out if they close their browser > > 29 @app.before_request > 30 def before_request(): > 31 g.permission = config.permission_problem() > 32 g.current_time = datetime.datetime.now().strftime('%Y-%m-%d > %H:%M:%S') > 33 session.permanent = True > 34 app.permanent_session_lifetime = datetime.timedelta(minutes=60) > 35 > 36 if current_user.is_authenticated(): > 37 user = User.query.filter_by(email=current_user.email).first() > 38 user.current_login_at = datetime.datetime.now() > 39 db.session.commit() > > Matt > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -- Best, Minglangjun Li -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidnieder at gmx.de Tue Sep 15 10:29:22 2015 From: davidnieder at gmx.de (David Nieder) Date: Tue, 15 Sep 2015 10:29:22 +0200 Subject: [Flask] Expiring login sessions In-Reply-To: References: Message-ID: <55F7D6E2.6020407@gmx.de> On 14.09.2015 14:46, Matt Shields wrote: > Below is what I had put in when I was building the login and sessions. > I've tried setting the app.permanent_session_lifetime to a specific amount > of time so that the user will get logged out and it doesn't seem to work. > Also, besides logging them out after a specific amount of time, I'd like to > have them logged out if they close their browser > > 29 @app.before_request > 30 def before_request(): > 31 g.permission = config.permission_problem() > 32 g.current_time = datetime.datetime.now().strftime('%Y-%m-%d > %H:%M:%S') > 33 session.permanent = True > 34 app.permanent_session_lifetime = datetime.timedelta(minutes=60) > 35 > 36 if current_user.is_authenticated(): > 37 user = User.query.filter_by(email=current_user.email).first() > 38 user.current_login_at = datetime.datetime.now() > 39 db.session.commit() > > Matt > Hello Matt The current_user.is_authenticated call looks like you use flask-login. If that is the case you need to set the lifetime of the "remember_me" cookie: https://flask-login.readthedocs.org/en/latest/#cookie-settings Also: as far as I know a cookie has either an expiration date or if that field is empty, the cookie gets removed when the browser is closed. Therefor the behavior you describe can't be accomplished with the cookie alone. David From coreybrett at gmail.com Tue Sep 15 13:53:09 2015 From: coreybrett at gmail.com (Corey Boyle) Date: Tue, 15 Sep 2015 07:53:09 -0400 Subject: [Flask] Scheduled tasks Message-ID: Is it possible to schedule a task/function to run every x minutes in Flask? Or would I need to user a separate worker process for that? I?m just looking to log some stats about my web app on an ongoing basis. From david at davidbaumgold.com Tue Sep 15 13:55:40 2015 From: david at davidbaumgold.com (David Baumgold) Date: Tue, 15 Sep 2015 07:55:40 -0400 Subject: [Flask] Scheduled tasks In-Reply-To: References: Message-ID: You?ll need a task queue for that. I recommend Celery:?http://www.celeryproject.org/ David Baumgold On September 15, 2015 at 7:54:05 AM, Corey Boyle (coreybrett at gmail.com) wrote: Is it possible to schedule a task/function to run every x minutes in Flask? Or would I need to user a separate worker process for that? I?m just looking to log some stats about my web app on an ongoing basis. _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From bk at breadtech.com Wed Sep 16 00:04:49 2015 From: bk at breadtech.com (Brian Kim) Date: Tue, 15 Sep 2015 18:04:49 -0400 Subject: [Flask] plans for 1.0 release Message-ID: Dear flask devs, I was wondering what the hold up is on making a 1.0 release for flask? I am a huge fan of this library and the lack of a 1.0 makes me feel like the product is still in a beta state. Best, BK -------------- next part -------------- An HTML attachment was scrubbed... URL: From linnchord at gmail.com Wed Sep 16 17:57:04 2015 From: linnchord at gmail.com (linnchord) Date: Wed, 16 Sep 2015 23:57:04 +0800 Subject: [Flask] Scheduled tasks In-Reply-To: References: Message-ID: Maybe you need RQ (http://python-rq.org/) for that, it's like Celery but more concise than it. 2015-09-15 19:55 GMT+08:00 David Baumgold : > You?ll need a task queue for that. I recommend Celery: > http://www.celeryproject.org/ > > > David Baumgold > > On September 15, 2015 at 7:54:05 AM, Corey Boyle (coreybrett at gmail.com) > wrote: > > Is it possible to schedule a task/function to run every x minutes in > Flask? Or would I need to user a separate worker process for that? I?m > just looking to log some stats about my web app on an ongoing basis. > _______________________________________________ > 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 canhosgor at gmail.com Thu Sep 17 14:34:11 2015 From: canhosgor at gmail.com (=?UTF-8?B?Q2FuIEhvxZ9nw7Zy?=) Date: Thu, 17 Sep 2015 15:34:11 +0300 Subject: [Flask] Scheduled tasks In-Reply-To: References: Message-ID: If think using a task queue will be overkill, you can simply write your function as a route in your app. And then, set up a cron job that periodically does a curl request to your route. On Tue, Sep 15, 2015 at 2:53 PM, Corey Boyle wrote: > Is it possible to schedule a task/function to run every x minutes in > Flask? Or would I need to user a separate worker process for that? I?m > just looking to log some stats about my web app on an ongoing basis. > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask From coreybrett at gmail.com Thu Sep 17 14:39:07 2015 From: coreybrett at gmail.com (Corey Boyle) Date: Thu, 17 Sep 2015 08:39:07 -0400 Subject: [Flask] Scheduled tasks In-Reply-To: References: Message-ID: I like that! Simple, but effective. Now that I think about it, that's how Moodle works too. On Thu, Sep 17, 2015 at 8:34 AM, Can Ho?g?r wrote: > If think using a task queue will be overkill, you can simply write > your function as a route in your app. And then, set up a cron job that > periodically does a curl request to your route. > > On Tue, Sep 15, 2015 at 2:53 PM, Corey Boyle wrote: >> Is it possible to schedule a task/function to run every x minutes in >> Flask? Or would I need to user a separate worker process for that? I?m >> just looking to log some stats about my web app on an ongoing basis. >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask From luca at lesinigo.it Fri Sep 18 09:32:20 2015 From: luca at lesinigo.it (Luca Lesinigo) Date: Fri, 18 Sep 2015 09:32:20 +0200 Subject: [Flask] Scheduled tasks In-Reply-To: References: Message-ID: <6AD2FC49-A086-4182-B17B-75949226D8B2@lesinigo.it> Il giorno 17/set/2015, alle ore 14:39, Corey Boyle ha scritto: > I like that! Simple, but effective. > Now that I think about it, that's how Moodle works too. For that kind of thing I usually spawn one or more python threads before calling app.run() and then use queues (queue.Queue() from standard library) for communication between Flask threads (handling requests) and my threads (doing my stuff) -- Luca Lesinigo From robertlagrant at gmail.com Sat Sep 19 08:05:49 2015 From: robertlagrant at gmail.com (Robert Grant) Date: Sat, 19 Sep 2015 08:05:49 +0200 Subject: [Flask] Object-level permissions? Message-ID: <7959280187243366253@unknownmsgid> Hi all! Is there an equivalent to something like django-guardian available as a flask extension? It associates a user permission with an individual object (e.g. Person1 is admin of Company3). Using SQLAlchemy, in case it makes a difference. Thanks! Sent from my phone -------------- next part -------------- An HTML attachment was scrubbed... URL: From fouad.chennouf at gmail.com Sat Sep 19 11:03:50 2015 From: fouad.chennouf at gmail.com (fouad CHENNOUF) Date: Sat, 19 Sep 2015 10:03:50 +0100 Subject: [Flask] Object-level permissions? In-Reply-To: <7959280187243366253@unknownmsgid> References: <7959280187243366253@unknownmsgid> Message-ID: Hi Robert, You can almost do it with flask-security. the extension has a role management feature, you just need to link the role with the Company and it should work fine. If you need to add attributes in your relations between persons and role(user rights) or between role and company (group rights) you'll have to move from many to many relationship in sqlalchemy to association object. *______________________________________________________________* *Fouad CHENNOUF* *CTO and Co-founder of Wilab **(Web/Software/Mobile app development)* *(+33).06.29.23.44.73 / * *(+213).06.73.24.84.33 * * * 2015-09-19 7:05 GMT+01:00 Robert Grant : > Hi all! Is there an equivalent to something like django-guardian available > as a flask extension? It associates a user permission with an individual > object (e.g. Person1 is admin of Company3). Using SQLAlchemy, in case it > makes a difference. > > Thanks! > > Sent from my phone > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Mon Sep 21 18:39:48 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Mon, 21 Sep 2015 12:39:48 -0400 Subject: [Flask] Usage of session and g variables Message-ID: Hi, all. I am currently in the process of designing a website for a friends restaurant. I am planning to deploy the website through Heroku. I am just hoping to keep the costs down for my friend and learn a few things. I want to create a portion of the website that can be used for online checkout. I aiming for something similar to any ordering application, i.e. grubhub. I have some of the website together, I will post a link to its git repository below. One thing I have been struggling to understand with Flask is the use of session variables and global (g) variables. My purpose is to create a shopping cart, where I can store what a user wants to order. So far I have tried creating a standard python array and a variable within the view function for the orders page. This is in principle to store which items the user selects and to store the total price. The items selected and the total price are then rendered appropriately. The obvious problem with this method is that the objects are cleared after each request. So the item selected and the total price only reflects the previous request. One way to get around this is to create a global variable outside of the route for a given view function. I believe this is incorrect because it stores the data even after I go elsewhere on the site. Creating session variables or global variables for that matter and then updating them as selections are made seems to have the same issue as using python storage variables within the view function. Please see these links for the view function I am talking about. Declaration of variables (using the g object in this case): https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 Here is where I look for the user to add an item, and attempt to store the data: https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 I am at point now where I am not sure that the usage of session and g variables are what I am trying to use them for. I wonder if this is now a case where using a database is the technically correct/better thing to do. My questions are: Is my use of global variables problematic? Is there a way to use session and/or g for this purpose? Am I better off using a database for storing this data? Please keep in mind I brand new to using flask and web development in general. I look forward to hearing back to any responses. Feel free to cover basics of web development, because I am sure that I am missing some. If anyone is interested or wants to see the website in action, here is the entire git repository: https://github.com/callmeskywalker/casa-sabor Thanks, Kyle -------------- next part -------------- An HTML attachment was scrubbed... URL: From coreybrett at gmail.com Mon Sep 21 19:11:12 2015 From: coreybrett at gmail.com (Corey Boyle) Date: Mon, 21 Sep 2015 13:11:12 -0400 Subject: [Flask] Usage of session and g variables In-Reply-To: References: Message-ID: I can't answer your question directly, but maybe you could get some inspiration from this. http://satchless.com/ On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor wrote: > Hi, all. > > > I am currently in the process of designing a website for a friends > restaurant. I am planning to deploy the website through Heroku. I am just > hoping to keep the costs down for my friend and learn a few things. > > I want to create a portion of the website that can be used for online > checkout. I aiming for something similar to any ordering application, i.e. > grubhub. I have some of the website together, I will post a link to its git > repository below. > > One thing I have been struggling to understand with Flask is the use of > session variables and global (g) variables. My purpose is to create a > shopping cart, where I can store what a user wants to order. > > So far I have tried creating a standard python array and a variable within > the view function for the orders page. This is in principle to store which > items the user selects and to store the total price. The items selected and > the total price are then rendered appropriately. The obvious problem with > this method is that the objects are cleared after each request. So the item > selected and the total price only reflects the previous request. > > One way to get around this is to create a global variable outside of the > route for a given view function. I believe this is incorrect because it > stores the data even after I go elsewhere on the site. > > Creating session variables or global variables for that matter and then > updating them as selections are made seems to have the same issue as using > python storage variables within the view function. Please see these links > for the view function I am talking about. > > Declaration of variables (using the g object in this case): > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 > Here is where I look for the user to add an item, and attempt to store the > data: > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 > > I am at point now where I am not sure that the usage of session and g > variables are what I am trying to use them for. I wonder if this is now a > case where using a database is the technically correct/better thing to do. > > My questions are: > Is my use of global variables problematic? > Is there a way to use session and/or g for this purpose? > Am I better off using a database for storing this data? > > Please keep in mind I brand new to using flask and web development in > general. I look forward to hearing back to any responses. Feel free to cover > basics of web development, because I am sure that I am missing some. > > If anyone is interested or wants to see the website in action, here is the > entire git repository: > https://github.com/callmeskywalker/casa-sabor > > > Thanks, Kyle > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > From klawlor419 at gmail.com Mon Sep 21 19:39:31 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Mon, 21 Sep 2015 13:39:31 -0400 Subject: [Flask] Usage of session and g variables In-Reply-To: References: Message-ID: Thanks for the reference. It looks like it could be a very useful tool. I will consider re-writing things and using that as well. Do you have or know of any examples using satchless with Flask? My original questions still stand, looking forward to more responses. On Mon, Sep 21, 2015 at 1:11 PM, Corey Boyle wrote: > I can't answer your question directly, but maybe you could get some > inspiration from this. > http://satchless.com/ > > On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor > wrote: > > Hi, all. > > > > > > I am currently in the process of designing a website for a friends > > restaurant. I am planning to deploy the website through Heroku. I am just > > hoping to keep the costs down for my friend and learn a few things. > > > > I want to create a portion of the website that can be used for online > > checkout. I aiming for something similar to any ordering application, > i.e. > > grubhub. I have some of the website together, I will post a link to its > git > > repository below. > > > > One thing I have been struggling to understand with Flask is the use of > > session variables and global (g) variables. My purpose is to create a > > shopping cart, where I can store what a user wants to order. > > > > So far I have tried creating a standard python array and a variable > within > > the view function for the orders page. This is in principle to store > which > > items the user selects and to store the total price. The items selected > and > > the total price are then rendered appropriately. The obvious problem with > > this method is that the objects are cleared after each request. So the > item > > selected and the total price only reflects the previous request. > > > > One way to get around this is to create a global variable outside of the > > route for a given view function. I believe this is incorrect because it > > stores the data even after I go elsewhere on the site. > > > > Creating session variables or global variables for that matter and then > > updating them as selections are made seems to have the same issue as > using > > python storage variables within the view function. Please see these links > > for the view function I am talking about. > > > > Declaration of variables (using the g object in this case): > > > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 > > Here is where I look for the user to add an item, and attempt to store > the > > data: > > > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 > > > > I am at point now where I am not sure that the usage of session and g > > variables are what I am trying to use them for. I wonder if this is now a > > case where using a database is the technically correct/better thing to > do. > > > > My questions are: > > Is my use of global variables problematic? > > Is there a way to use session and/or g for this purpose? > > Am I better off using a database for storing this data? > > > > Please keep in mind I brand new to using flask and web development in > > general. I look forward to hearing back to any responses. Feel free to > cover > > basics of web development, because I am sure that I am missing some. > > > > If anyone is interested or wants to see the website in action, here is > the > > entire git repository: > > https://github.com/callmeskywalker/casa-sabor > > > > > > Thanks, Kyle > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tamasiaina at gmail.com Mon Sep 21 19:44:20 2015 From: tamasiaina at gmail.com (Jonathan Chen) Date: Mon, 21 Sep 2015 10:44:20 -0700 Subject: [Flask] Usage of session and g variables In-Reply-To: References: Message-ID: Sessions will persist through secured cookies while the g variable only persist with each request. So for a shopping cart a session object would be better to use. If you wanted to store temporarily information like for instance a credit card or something similar you can put it in the g variable to be process the credit card information later. ~Jonathan C. On Mon, Sep 21, 2015 at 10:11 AM, Corey Boyle wrote: > I can't answer your question directly, but maybe you could get some > inspiration from this. > http://satchless.com/ > > On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor > wrote: > > Hi, all. > > > > > > I am currently in the process of designing a website for a friends > > restaurant. I am planning to deploy the website through Heroku. I am just > > hoping to keep the costs down for my friend and learn a few things. > > > > I want to create a portion of the website that can be used for online > > checkout. I aiming for something similar to any ordering application, > i.e. > > grubhub. I have some of the website together, I will post a link to its > git > > repository below. > > > > One thing I have been struggling to understand with Flask is the use of > > session variables and global (g) variables. My purpose is to create a > > shopping cart, where I can store what a user wants to order. > > > > So far I have tried creating a standard python array and a variable > within > > the view function for the orders page. This is in principle to store > which > > items the user selects and to store the total price. The items selected > and > > the total price are then rendered appropriately. The obvious problem with > > this method is that the objects are cleared after each request. So the > item > > selected and the total price only reflects the previous request. > > > > One way to get around this is to create a global variable outside of the > > route for a given view function. I believe this is incorrect because it > > stores the data even after I go elsewhere on the site. > > > > Creating session variables or global variables for that matter and then > > updating them as selections are made seems to have the same issue as > using > > python storage variables within the view function. Please see these links > > for the view function I am talking about. > > > > Declaration of variables (using the g object in this case): > > > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 > > Here is where I look for the user to add an item, and attempt to store > the > > data: > > > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 > > > > I am at point now where I am not sure that the usage of session and g > > variables are what I am trying to use them for. I wonder if this is now a > > case where using a database is the technically correct/better thing to > do. > > > > My questions are: > > Is my use of global variables problematic? > > Is there a way to use session and/or g for this purpose? > > Am I better off using a database for storing this data? > > > > Please keep in mind I brand new to using flask and web development in > > general. I look forward to hearing back to any responses. Feel free to > cover > > basics of web development, because I am sure that I am missing some. > > > > If anyone is interested or wants to see the website in action, here is > the > > entire git repository: > > https://github.com/callmeskywalker/casa-sabor > > > > > > Thanks, Kyle > > > > _______________________________________________ > > 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 jeff at jeffwidman.com Mon Sep 21 22:48:02 2015 From: jeff at jeffwidman.com (Jeff Widman) Date: Mon, 21 Sep 2015 13:48:02 -0700 Subject: [Flask] Usage of session and g variables In-Reply-To: References: Message-ID: If at all possible, avoid credit card data ever directly touching your server. It's a huge security risk that's really, really hard to get right, plus there's a bunch of hoops related to PCI compliance. Instead if you're rolling your own shopping cart, just use something like Stripe's javascript for the actual payment processing so that the credit card data goes straight from the client to Stripe's servers, and then you only need store the callback from Stripe that the customer's payment 'succeeeded', without actually storing the underlying data. ? On Mon, Sep 21, 2015 at 10:44 AM, Jonathan Chen wrote: > Sessions will persist through secured cookies while the g variable only > persist with each request. So for a shopping cart a session object would be > better to use. > > If you wanted to store temporarily information like for instance a credit > card or something similar you can put it in the g variable to be process > the credit card information later. > > > ~Jonathan C. > > On Mon, Sep 21, 2015 at 10:11 AM, Corey Boyle > wrote: > >> I can't answer your question directly, but maybe you could get some >> inspiration from this. >> http://satchless.com/ >> >> On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor >> wrote: >> > Hi, all. >> > >> > >> > I am currently in the process of designing a website for a friends >> > restaurant. I am planning to deploy the website through Heroku. I am >> just >> > hoping to keep the costs down for my friend and learn a few things. >> > >> > I want to create a portion of the website that can be used for online >> > checkout. I aiming for something similar to any ordering application, >> i.e. >> > grubhub. I have some of the website together, I will post a link to its >> git >> > repository below. >> > >> > One thing I have been struggling to understand with Flask is the use of >> > session variables and global (g) variables. My purpose is to create a >> > shopping cart, where I can store what a user wants to order. >> > >> > So far I have tried creating a standard python array and a variable >> within >> > the view function for the orders page. This is in principle to store >> which >> > items the user selects and to store the total price. The items selected >> and >> > the total price are then rendered appropriately. The obvious problem >> with >> > this method is that the objects are cleared after each request. So the >> item >> > selected and the total price only reflects the previous request. >> > >> > One way to get around this is to create a global variable outside of the >> > route for a given view function. I believe this is incorrect because it >> > stores the data even after I go elsewhere on the site. >> > >> > Creating session variables or global variables for that matter and then >> > updating them as selections are made seems to have the same issue as >> using >> > python storage variables within the view function. Please see these >> links >> > for the view function I am talking about. >> > >> > Declaration of variables (using the g object in this case): >> > >> https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 >> > Here is where I look for the user to add an item, and attempt to store >> the >> > data: >> > >> https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 >> > >> > I am at point now where I am not sure that the usage of session and g >> > variables are what I am trying to use them for. I wonder if this is now >> a >> > case where using a database is the technically correct/better thing to >> do. >> > >> > My questions are: >> > Is my use of global variables problematic? >> > Is there a way to use session and/or g for this purpose? >> > Am I better off using a database for storing this data? >> > >> > Please keep in mind I brand new to using flask and web development in >> > general. I look forward to hearing back to any responses. Feel free to >> cover >> > basics of web development, because I am sure that I am missing some. >> > >> > If anyone is interested or wants to see the website in action, here is >> the >> > entire git repository: >> > https://github.com/callmeskywalker/casa-sabor >> > >> > >> > Thanks, Kyle >> > >> > _______________________________________________ >> > 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 >> > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -- *Jeff Widman* jeffwidman.com | 740-WIDMAN-J (943-6265) <>< -------------- next part -------------- An HTML attachment was scrubbed... URL: From fededelgado at outlook.com Mon Sep 21 23:45:23 2015 From: fededelgado at outlook.com (Federico Delgado Doyle) Date: Mon, 21 Sep 2015 14:45:23 -0700 Subject: [Flask] Usage of session and g variables In-Reply-To: References: , , , Message-ID: +100 to what Jeff said. Let someone else run with the risks of payment information/handling. More related to your question about session and g. If you must use anything sensitive on the session, be sure to use server side storage and have nothing travelling inside the cookie except for the session identifier (which I also would recommend to regenerate at appropriate points to avoid any session pinning). Federico From: jeff at jeffwidman.com Date: Mon, 21 Sep 2015 13:48:02 -0700 To: flask at python.org Subject: Re: [Flask] Usage of session and g variables If at all possible, avoid credit card data ever directly touching your server. It's a huge security risk that's really, really hard to get right, plus there's a bunch of hoops related to PCI compliance. Instead if you're rolling your own shopping cart, just use something like Stripe's javascript for the actual payment processing so that the credit card data goes straight from the client to Stripe's servers, and then you only need store the callback from Stripe that the customer's payment 'succeeeded', without actually storing the underlying data. ? On Mon, Sep 21, 2015 at 10:44 AM, Jonathan Chen wrote: Sessions will persist through secured cookies while the g variable only persist with each request. So for a shopping cart a session object would be better to use. If you wanted to store temporarily information like for instance a credit card or something similar you can put it in the g variable to be process the credit card information later. ~Jonathan C. On Mon, Sep 21, 2015 at 10:11 AM, Corey Boyle wrote: I can't answer your question directly, but maybe you could get some inspiration from this. http://satchless.com/ On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor wrote: > Hi, all. > > > I am currently in the process of designing a website for a friends > restaurant. I am planning to deploy the website through Heroku. I am just > hoping to keep the costs down for my friend and learn a few things. > > I want to create a portion of the website that can be used for online > checkout. I aiming for something similar to any ordering application, i.e. > grubhub. I have some of the website together, I will post a link to its git > repository below. > > One thing I have been struggling to understand with Flask is the use of > session variables and global (g) variables. My purpose is to create a > shopping cart, where I can store what a user wants to order. > > So far I have tried creating a standard python array and a variable within > the view function for the orders page. This is in principle to store which > items the user selects and to store the total price. The items selected and > the total price are then rendered appropriately. The obvious problem with > this method is that the objects are cleared after each request. So the item > selected and the total price only reflects the previous request. > > One way to get around this is to create a global variable outside of the > route for a given view function. I believe this is incorrect because it > stores the data even after I go elsewhere on the site. > > Creating session variables or global variables for that matter and then > updating them as selections are made seems to have the same issue as using > python storage variables within the view function. Please see these links > for the view function I am talking about. > > Declaration of variables (using the g object in this case): > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 > Here is where I look for the user to add an item, and attempt to store the > data: > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 > > I am at point now where I am not sure that the usage of session and g > variables are what I am trying to use them for. I wonder if this is now a > case where using a database is the technically correct/better thing to do. > > My questions are: > Is my use of global variables problematic? > Is there a way to use session and/or g for this purpose? > Am I better off using a database for storing this data? > > Please keep in mind I brand new to using flask and web development in > general. I look forward to hearing back to any responses. Feel free to cover > basics of web development, because I am sure that I am missing some. > > If anyone is interested or wants to see the website in action, here is the > entire git repository: > https://github.com/callmeskywalker/casa-sabor > > > Thanks, Kyle > > _______________________________________________ > 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 _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -- Jeff Widmanjeffwidman.com | 740-WIDMAN-J (943-6265) <>< _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Tue Sep 22 03:29:02 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Mon, 21 Sep 2015 21:29:02 -0400 Subject: [Flask] Flask Digest, Vol 3, Issue 22 In-Reply-To: References: Message-ID: Hi, all. Thank you very much for the responses. @Jeff, I am actually planning on making use of the Stripe API and service. Currently I am just trying to build the shopping cart on the client side. I am taking it one step at a time. @Jonathan, Could you take a look at my code to see if I am using the session object correctly? I am puzzled with the current behaviour I am seeing. I made changes to my code, I am now attempting to store the items requested and compute the total price via the *session* object. Here is a link to the code: https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 The behaviour I am seeing is the same as before. The variables are *not* remembered from the previous request. I am sure there is a trivial mistake in my code somewhere. Another recent change I made was adding this line (Which is just a secret key config.): https://github.com/callmeskywalker/casa-sabor/blob/master/app/__init__.py#L21 I thought perhaps the session object will only work if there is a secret key defined, but this did not seem to change the behaviour. Hoping to hear more soon, Kyle. On Mon, Sep 21, 2015 at 4:48 PM, wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Usage of session and g variables (Jonathan Chen) > 2. Re: Usage of session and g variables (Jeff Widman) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 21 Sep 2015 10:44:20 -0700 > From: Jonathan Chen > Cc: flask at python.org > Subject: Re: [Flask] Usage of session and g variables > Message-ID: > cJLUL26ss5r-NVg_SYCASuJg at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Sessions will persist through secured cookies while the g variable only > persist with each request. So for a shopping cart a session object would be > better to use. > > If you wanted to store temporarily information like for instance a credit > card or something similar you can put it in the g variable to be process > the credit card information later. > > > ~Jonathan C. > > On Mon, Sep 21, 2015 at 10:11 AM, Corey Boyle > wrote: > > > I can't answer your question directly, but maybe you could get some > > inspiration from this. > > http://satchless.com/ > > > > On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor > > wrote: > > > Hi, all. > > > > > > > > > I am currently in the process of designing a website for a friends > > > restaurant. I am planning to deploy the website through Heroku. I am > just > > > hoping to keep the costs down for my friend and learn a few things. > > > > > > I want to create a portion of the website that can be used for online > > > checkout. I aiming for something similar to any ordering application, > > i.e. > > > grubhub. I have some of the website together, I will post a link to its > > git > > > repository below. > > > > > > One thing I have been struggling to understand with Flask is the use of > > > session variables and global (g) variables. My purpose is to create a > > > shopping cart, where I can store what a user wants to order. > > > > > > So far I have tried creating a standard python array and a variable > > within > > > the view function for the orders page. This is in principle to store > > which > > > items the user selects and to store the total price. The items selected > > and > > > the total price are then rendered appropriately. The obvious problem > with > > > this method is that the objects are cleared after each request. So the > > item > > > selected and the total price only reflects the previous request. > > > > > > One way to get around this is to create a global variable outside of > the > > > route for a given view function. I believe this is incorrect because it > > > stores the data even after I go elsewhere on the site. > > > > > > Creating session variables or global variables for that matter and then > > > updating them as selections are made seems to have the same issue as > > using > > > python storage variables within the view function. Please see these > links > > > for the view function I am talking about. > > > > > > Declaration of variables (using the g object in this case): > > > > > > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 > > > Here is where I look for the user to add an item, and attempt to store > > the > > > data: > > > > > > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 > > > > > > I am at point now where I am not sure that the usage of session and g > > > variables are what I am trying to use them for. I wonder if this is > now a > > > case where using a database is the technically correct/better thing to > > do. > > > > > > My questions are: > > > Is my use of global variables problematic? > > > Is there a way to use session and/or g for this purpose? > > > Am I better off using a database for storing this data? > > > > > > Please keep in mind I brand new to using flask and web development in > > > general. I look forward to hearing back to any responses. Feel free to > > cover > > > basics of web development, because I am sure that I am missing some. > > > > > > If anyone is interested or wants to see the website in action, here is > > the > > > entire git repository: > > > https://github.com/callmeskywalker/casa-sabor > > > > > > > > > Thanks, Kyle > > > > > > _______________________________________________ > > > 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: < > http://mail.python.org/pipermail/flask/attachments/20150921/1a8cd178/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Mon, 21 Sep 2015 13:48:02 -0700 > From: Jeff Widman > To: flask at python.org > Subject: Re: [Flask] Usage of session and g variables > Message-ID: > PncJgLaAn2XrBmEy+ryX0OOTqGmg at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > If at all possible, avoid credit card data ever directly touching your > server. > > It's a huge security risk that's really, really hard to get right, plus > there's a bunch of hoops related to PCI compliance. > > Instead if you're rolling your own shopping cart, just use something like > Stripe's javascript for the actual payment processing so that the credit > card data goes straight from the client to Stripe's servers, and then you > only need store the callback from Stripe that the customer's payment > 'succeeeded', without actually storing the underlying data. > > > ? > > On Mon, Sep 21, 2015 at 10:44 AM, Jonathan Chen > wrote: > > > Sessions will persist through secured cookies while the g variable only > > persist with each request. So for a shopping cart a session object would > be > > better to use. > > > > If you wanted to store temporarily information like for instance a credit > > card or something similar you can put it in the g variable to be process > > the credit card information later. > > > > > > ~Jonathan C. > > > > On Mon, Sep 21, 2015 at 10:11 AM, Corey Boyle > > wrote: > > > >> I can't answer your question directly, but maybe you could get some > >> inspiration from this. > >> http://satchless.com/ > >> > >> On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor > >> wrote: > >> > Hi, all. > >> > > >> > > >> > I am currently in the process of designing a website for a friends > >> > restaurant. I am planning to deploy the website through Heroku. I am > >> just > >> > hoping to keep the costs down for my friend and learn a few things. > >> > > >> > I want to create a portion of the website that can be used for online > >> > checkout. I aiming for something similar to any ordering application, > >> i.e. > >> > grubhub. I have some of the website together, I will post a link to > its > >> git > >> > repository below. > >> > > >> > One thing I have been struggling to understand with Flask is the use > of > >> > session variables and global (g) variables. My purpose is to create a > >> > shopping cart, where I can store what a user wants to order. > >> > > >> > So far I have tried creating a standard python array and a variable > >> within > >> > the view function for the orders page. This is in principle to store > >> which > >> > items the user selects and to store the total price. The items > selected > >> and > >> > the total price are then rendered appropriately. The obvious problem > >> with > >> > this method is that the objects are cleared after each request. So the > >> item > >> > selected and the total price only reflects the previous request. > >> > > >> > One way to get around this is to create a global variable outside of > the > >> > route for a given view function. I believe this is incorrect because > it > >> > stores the data even after I go elsewhere on the site. > >> > > >> > Creating session variables or global variables for that matter and > then > >> > updating them as selections are made seems to have the same issue as > >> using > >> > python storage variables within the view function. Please see these > >> links > >> > for the view function I am talking about. > >> > > >> > Declaration of variables (using the g object in this case): > >> > > >> > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 > >> > Here is where I look for the user to add an item, and attempt to store > >> the > >> > data: > >> > > >> > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 > >> > > >> > I am at point now where I am not sure that the usage of session and g > >> > variables are what I am trying to use them for. I wonder if this is > now > >> a > >> > case where using a database is the technically correct/better thing to > >> do. > >> > > >> > My questions are: > >> > Is my use of global variables problematic? > >> > Is there a way to use session and/or g for this purpose? > >> > Am I better off using a database for storing this data? > >> > > >> > Please keep in mind I brand new to using flask and web development in > >> > general. I look forward to hearing back to any responses. Feel free to > >> cover > >> > basics of web development, because I am sure that I am missing some. > >> > > >> > If anyone is interested or wants to see the website in action, here is > >> the > >> > entire git repository: > >> > https://github.com/callmeskywalker/casa-sabor > >> > > >> > > >> > Thanks, Kyle > >> > > >> > _______________________________________________ > >> > 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 > >> > > > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > > -- > > *Jeff Widman* > jeffwidman.com | 740-WIDMAN-J (943-6265) > <>< > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20150921/9c117a24/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 3, Issue 22 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Tue Sep 22 05:04:36 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Mon, 21 Sep 2015 23:04:36 -0400 Subject: [Flask] Flask Digest, Vol 3, Issue 22 In-Reply-To: References: Message-ID: @Federico and @Jeff, I should add that as far as I know the Stripe API is just for the credit card info and the purchase validation. Does it also have a tool set to help build the shopping cart (a list of items the customer wants to purchase)? I plan to have a redirect button on the shopping cart to move on to checkout, on this checkout page I will implement the Stripe Checkout. For now I am stuck because I cannot generate a list storing the items. @Federico, Does storing sensitive information on the server side count as keeping that information inside your view functions file? I think the most sensitive information I will be storing is the purchase token from the Stripe API. Cheers, Kyle. P.S. Apologies if this message is a duplicate for anyone. On Mon, Sep 21, 2015 at 9:29 PM, Kyle Lawlor wrote: > Hi, all. > > Thank you very much for the responses. > > @Jeff, I am actually planning on making use of the Stripe API and service. > Currently I am just trying to build the shopping cart on the client side. I > am taking it one step at a time. > > @Jonathan, Could you take a look at my code to see if I am using the > session object correctly? I am puzzled with the current behaviour I am > seeing. I made changes to my code, I am now attempting to store the items > requested and compute the total price via the *session* object. Here is a > link to the code: > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 > > The behaviour I am seeing is the same as before. The variables are *not* > remembered from the previous request. I am sure there is a trivial mistake > in my code somewhere. > > Another recent change I made was adding this line (Which is just a secret > key config.): > > https://github.com/callmeskywalker/casa-sabor/blob/master/app/__init__.py#L21 > I thought perhaps the session object will only work if there is a secret > key defined, but this did not seem to change the behaviour. > > Hoping to hear more soon, Kyle. > > On Mon, Sep 21, 2015 at 4:48 PM, wrote: > >> Send Flask mailing list submissions to >> flask at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> https://mail.python.org/mailman/listinfo/flask >> or, via email, send a message with subject or body 'help' to >> flask-request at python.org >> >> You can reach the person managing the list at >> flask-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Flask digest..." >> >> >> Today's Topics: >> >> 1. Re: Usage of session and g variables (Jonathan Chen) >> 2. Re: Usage of session and g variables (Jeff Widman) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Mon, 21 Sep 2015 10:44:20 -0700 >> From: Jonathan Chen >> Cc: flask at python.org >> Subject: Re: [Flask] Usage of session and g variables >> Message-ID: >> > cJLUL26ss5r-NVg_SYCASuJg at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" >> >> Sessions will persist through secured cookies while the g variable only >> persist with each request. So for a shopping cart a session object would >> be >> better to use. >> >> If you wanted to store temporarily information like for instance a credit >> card or something similar you can put it in the g variable to be process >> the credit card information later. >> >> >> ~Jonathan C. >> >> On Mon, Sep 21, 2015 at 10:11 AM, Corey Boyle >> wrote: >> >> > I can't answer your question directly, but maybe you could get some >> > inspiration from this. >> > http://satchless.com/ >> > >> > On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor >> > wrote: >> > > Hi, all. >> > > >> > > >> > > I am currently in the process of designing a website for a friends >> > > restaurant. I am planning to deploy the website through Heroku. I am >> just >> > > hoping to keep the costs down for my friend and learn a few things. >> > > >> > > I want to create a portion of the website that can be used for online >> > > checkout. I aiming for something similar to any ordering application, >> > i.e. >> > > grubhub. I have some of the website together, I will post a link to >> its >> > git >> > > repository below. >> > > >> > > One thing I have been struggling to understand with Flask is the use >> of >> > > session variables and global (g) variables. My purpose is to create a >> > > shopping cart, where I can store what a user wants to order. >> > > >> > > So far I have tried creating a standard python array and a variable >> > within >> > > the view function for the orders page. This is in principle to store >> > which >> > > items the user selects and to store the total price. The items >> selected >> > and >> > > the total price are then rendered appropriately. The obvious problem >> with >> > > this method is that the objects are cleared after each request. So the >> > item >> > > selected and the total price only reflects the previous request. >> > > >> > > One way to get around this is to create a global variable outside of >> the >> > > route for a given view function. I believe this is incorrect because >> it >> > > stores the data even after I go elsewhere on the site. >> > > >> > > Creating session variables or global variables for that matter and >> then >> > > updating them as selections are made seems to have the same issue as >> > using >> > > python storage variables within the view function. Please see these >> links >> > > for the view function I am talking about. >> > > >> > > Declaration of variables (using the g object in this case): >> > > >> > >> https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 >> > > Here is where I look for the user to add an item, and attempt to store >> > the >> > > data: >> > > >> > >> https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 >> > > >> > > I am at point now where I am not sure that the usage of session and g >> > > variables are what I am trying to use them for. I wonder if this is >> now a >> > > case where using a database is the technically correct/better thing to >> > do. >> > > >> > > My questions are: >> > > Is my use of global variables problematic? >> > > Is there a way to use session and/or g for this purpose? >> > > Am I better off using a database for storing this data? >> > > >> > > Please keep in mind I brand new to using flask and web development in >> > > general. I look forward to hearing back to any responses. Feel free to >> > cover >> > > basics of web development, because I am sure that I am missing some. >> > > >> > > If anyone is interested or wants to see the website in action, here is >> > the >> > > entire git repository: >> > > https://github.com/callmeskywalker/casa-sabor >> > > >> > > >> > > Thanks, Kyle >> > > >> > > _______________________________________________ >> > > 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: < >> http://mail.python.org/pipermail/flask/attachments/20150921/1a8cd178/attachment-0001.html >> > >> >> ------------------------------ >> >> Message: 2 >> Date: Mon, 21 Sep 2015 13:48:02 -0700 >> From: Jeff Widman >> To: flask at python.org >> Subject: Re: [Flask] Usage of session and g variables >> Message-ID: >> > PncJgLaAn2XrBmEy+ryX0OOTqGmg at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" >> >> If at all possible, avoid credit card data ever directly touching your >> server. >> >> It's a huge security risk that's really, really hard to get right, plus >> there's a bunch of hoops related to PCI compliance. >> >> Instead if you're rolling your own shopping cart, just use something like >> Stripe's javascript for the actual payment processing so that the credit >> card data goes straight from the client to Stripe's servers, and then you >> only need store the callback from Stripe that the customer's payment >> 'succeeeded', without actually storing the underlying data. >> >> >> ? >> >> On Mon, Sep 21, 2015 at 10:44 AM, Jonathan Chen >> wrote: >> >> > Sessions will persist through secured cookies while the g variable only >> > persist with each request. So for a shopping cart a session object >> would be >> > better to use. >> > >> > If you wanted to store temporarily information like for instance a >> credit >> > card or something similar you can put it in the g variable to be process >> > the credit card information later. >> > >> > >> > ~Jonathan C. >> > >> > On Mon, Sep 21, 2015 at 10:11 AM, Corey Boyle >> > wrote: >> > >> >> I can't answer your question directly, but maybe you could get some >> >> inspiration from this. >> >> http://satchless.com/ >> >> >> >> On Mon, Sep 21, 2015 at 12:39 PM, Kyle Lawlor >> >> wrote: >> >> > Hi, all. >> >> > >> >> > >> >> > I am currently in the process of designing a website for a friends >> >> > restaurant. I am planning to deploy the website through Heroku. I am >> >> just >> >> > hoping to keep the costs down for my friend and learn a few things. >> >> > >> >> > I want to create a portion of the website that can be used for online >> >> > checkout. I aiming for something similar to any ordering application, >> >> i.e. >> >> > grubhub. I have some of the website together, I will post a link to >> its >> >> git >> >> > repository below. >> >> > >> >> > One thing I have been struggling to understand with Flask is the use >> of >> >> > session variables and global (g) variables. My purpose is to create a >> >> > shopping cart, where I can store what a user wants to order. >> >> > >> >> > So far I have tried creating a standard python array and a variable >> >> within >> >> > the view function for the orders page. This is in principle to store >> >> which >> >> > items the user selects and to store the total price. The items >> selected >> >> and >> >> > the total price are then rendered appropriately. The obvious problem >> >> with >> >> > this method is that the objects are cleared after each request. So >> the >> >> item >> >> > selected and the total price only reflects the previous request. >> >> > >> >> > One way to get around this is to create a global variable outside of >> the >> >> > route for a given view function. I believe this is incorrect because >> it >> >> > stores the data even after I go elsewhere on the site. >> >> > >> >> > Creating session variables or global variables for that matter and >> then >> >> > updating them as selections are made seems to have the same issue as >> >> using >> >> > python storage variables within the view function. Please see these >> >> links >> >> > for the view function I am talking about. >> >> > >> >> > Declaration of variables (using the g object in this case): >> >> > >> >> >> https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 >> >> > Here is where I look for the user to add an item, and attempt to >> store >> >> the >> >> > data: >> >> > >> >> >> https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L97 >> >> > >> >> > I am at point now where I am not sure that the usage of session and g >> >> > variables are what I am trying to use them for. I wonder if this is >> now >> >> a >> >> > case where using a database is the technically correct/better thing >> to >> >> do. >> >> > >> >> > My questions are: >> >> > Is my use of global variables problematic? >> >> > Is there a way to use session and/or g for this purpose? >> >> > Am I better off using a database for storing this data? >> >> > >> >> > Please keep in mind I brand new to using flask and web development in >> >> > general. I look forward to hearing back to any responses. Feel free >> to >> >> cover >> >> > basics of web development, because I am sure that I am missing some. >> >> > >> >> > If anyone is interested or wants to see the website in action, here >> is >> >> the >> >> > entire git repository: >> >> > https://github.com/callmeskywalker/casa-sabor >> >> > >> >> > >> >> > Thanks, Kyle >> >> > >> >> > _______________________________________________ >> >> > 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 >> >> >> > >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> > >> > >> >> >> -- >> >> *Jeff Widman* >> jeffwidman.com | 740-WIDMAN-J (943-6265) >> <>< >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: < >> http://mail.python.org/pipermail/flask/attachments/20150921/9c117a24/attachment.html >> > >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> >> ------------------------------ >> >> End of Flask Digest, Vol 3, Issue 22 >> ************************************ >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From and.damore at gmail.com Tue Sep 22 09:44:42 2015 From: and.damore at gmail.com (Andrea D'Amore) Date: Tue, 22 Sep 2015 09:44:42 +0200 Subject: [Flask] Usage of session and g variables In-Reply-To: References: Message-ID: On 21 September 2015 at 19:39, Kyle Lawlor wrote: > Thanks for the reference. It looks like it could be a very useful tool. I > will consider re-writing things and using that as well. Do you have or know > of any examples using satchless with Flask? I was going to suggest to look at satchless as well, but someone already did. There's an implementation of a satchless store [1] but it's built on Django. I was interested in adapting it and having a similar demo running on Flask, in order to do so and make Saleor running I had to approach Django (that I didn't know at all) and I found that I didn't like its structure and assumptions at all so eventually I dropped the idea, since it was more of an intellectual exercise than a need. If you manage to write a Satchless store relying on Flask please be sure to mention that here in list. [1] https://github.com/mirumee/saleor -- Andrea From davidnieder at gmx.de Tue Sep 22 13:05:54 2015 From: davidnieder at gmx.de (David Nieder) Date: Tue, 22 Sep 2015 13:05:54 +0200 Subject: [Flask] Flask Digest, Vol 3, Issue 22 In-Reply-To: References: Message-ID: <56013612.90604@gmx.de> On 22.09.2015 03:29, Kyle Lawlor wrote: > Hi, all. > > Thank you very much for the responses. > > @Jeff, I am actually planning on making use of the Stripe API and service. > Currently I am just trying to build the shopping cart on the client side. I > am taking it one step at a time. > > @Jonathan, Could you take a look at my code to see if I am using the > session object correctly? I am puzzled with the current behaviour I am > seeing. I made changes to my code, I am now attempting to store the items > requested and compute the total price via the *session* object. Here is a > link to the code: > https://github.com/callmeskywalker/casa-sabor/blob/master/app/main/views.py#L40 > Well, every time a request is made to '/order' you override the content of 'requested_item_record' with an empty list (line 40) and 'total_cost' with a zero (line 41). You should check first if there is already something in the session. e.g. if not 'requested_item_record' in session: session['requested_item_record'] = [] I cloned you project and simply commented out those two lines. It seems to work. Another tip for your repository: add a .gitignore to the root folder with sth like: *.py~ *.pyc venv/ You probably don't need/want those files tracked with git. David From frank.einstien at gmail.com Tue Sep 22 13:31:59 2015 From: frank.einstien at gmail.com (Jesvin Jose) Date: Tue, 22 Sep 2015 17:01:59 +0530 Subject: [Flask] Flask-SQLAlchemy create database once per test case Message-ID: I have the following base test class that enables Flask-SQLAlchemy, and creates a clean database and session for each test. from app import app, db class BaseTest(unittest.TestCase): def setUp(self): self.app_context = app.app_context() self.app_context.push() db.create_all() db.session.begin_nested() def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop() The disadvantage is that I pay the overhead of DDL for every test* method in the class. Could you help with that problem? I want the following structure: setUpClass - set up app context (whatever that is - without it I notice that db wont work) and run DDL commands setUp - create a nested transaction tearDown - reset the session for the next test tearDownClass - remove app context and database -- We dont beat the reaper by living longer. We beat the reaper by living well and living fully. The reaper will come for all of us. Question is, what do we do between the time we are born and the time he shows up? -Randy Pausch -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Tue Sep 22 15:08:45 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Tue, 22 Sep 2015 09:08:45 -0400 Subject: [Flask] Usage of session and g variables In-Reply-To: References: Message-ID: Hi all, Thanks to everyone for all of the responses. I really appreciate all of the feedback. @Andrea, I came across Saleor last night when I was reading about the Satchless API last night. I noticed that it was written in Django as well. I have worked only very briefly with Django. I am only just beginning my ventures in web development, this is really the first project I have taken on outside of hobby. I feel that I am pretty close to a solution for my purposes. I'm not sure if anyone has taken a look at my site but I think it is pretty efficient for a restaurants purposes. It is definitely still bare-bones, but I think I have a pretty nice way of generating the online menu. I use an ordered dict to store the menu and then make use of jinja2 looping to render the appropriate elements of the menu. I recently made a Jekyll blog site and I see my menu as the yml configuration file. I will spend some time learning the Satchless API and see if it can improve and/or simplify my site. I will try to think of things somewhat generically to maybe help building a satchless store built on Flask. In the meantime if anyone can help me diagnose the issues I am having with the session variables it will be greatly appreciated. I think I probably missing something in configuration or just doing something stupid. Best, Kyle. P.S. Apologies once again to those who receive duplicates of this message. On Tue, Sep 22, 2015 at 3:44 AM, Andrea D'Amore wrote: > On 21 September 2015 at 19:39, Kyle Lawlor wrote: > > Thanks for the reference. It looks like it could be a very useful tool. I > > will consider re-writing things and using that as well. Do you have or > know > > of any examples using satchless with Flask? > > I was going to suggest to look at satchless as well, but someone already > did. > > There's an implementation of a satchless store [1] but it's built on > Django. I was interested in adapting it and having a similar demo > running on Flask, in order to do so and make Saleor running I had to > approach Django (that I didn't know at all) and I found that I didn't > like its structure and assumptions at all so eventually I dropped the > idea, since it was more of an intellectual exercise than a need. > > If you manage to write a Satchless store relying on Flask please be > sure to mention that here in list. > > > [1] https://github.com/mirumee/saleor > > -- > Andrea > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Tue Sep 22 16:44:16 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Tue, 22 Sep 2015 10:44:16 -0400 Subject: [Flask] Usage of session and g variables In-Reply-To: <56015EB0.9050009@gmx.de> References: <56015EB0.9050009@gmx.de> Message-ID: Hi, David. I apologize, I completely missed your response. I'm glad you brought it to my attention. I have made a mess out of this thread somehow. Thanks a lot for taking a look at this for me and solving my problem! I understand what I was doing wrong now (head-slap). Also I will add those types of files to the .gitignore in the future. Thanks again, Kyle Hi Kyle! Have you seen the response I wrote? [1]. > You maybe missed it because I responded to the second thread > you started [2]. > > > Cheers > David > > [1] https://mail.python.org/pipermail/flask/2015-September/000100.html > [2] https://mail.python.org/pipermail/flask/2015-September/000097.html > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kajocina at gmail.com Tue Sep 22 18:38:11 2015 From: kajocina at gmail.com (Piotr Grabowski) Date: Tue, 22 Sep 2015 18:38:11 +0200 Subject: [Flask] Flask execute system command / wait / return result ? Message-ID: Hi! I am in a phase of planning a web application for my group (academic research) and would love to get some advice or input from more advanced Flask users/devs. We developed a bioinformatics tool that we run from a command line, it's run simply as ./tool_binary , so pretty standard stuff. We also are trying to turn this into an extremely easy-to-use tool for biologists and are looking for a proper online framework. We decided that Flask could be a great solution to keep the whole framework running. (already made it work on Galaxy, but we want to keep it ultra-simple and nice-looking) However, does anyone know if Flask could handle an execution of such command line tool, wait for the tool to finish and send back the user the generated resulting file ? Best regards, Piotr -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidnieder at gmx.de Wed Sep 23 01:09:56 2015 From: davidnieder at gmx.de (David Nieder) Date: Wed, 23 Sep 2015 01:09:56 +0200 Subject: [Flask] Flask execute system command / wait / return result ? In-Reply-To: References: Message-ID: <5601DFC4.5030308@gmx.de> On 22.09.2015 18:38, Piotr Grabowski wrote: > Hi! > > I am in a phase of planning a web application for my group (academic > research) and would love to get some advice or input from more advanced > Flask users/devs. > > We developed a bioinformatics tool that we run from a command line, it's > run simply as ./tool_binary , so pretty standard stuff. > > We also are trying to turn this into an extremely easy-to-use tool for > biologists and are looking for a proper online framework. We decided that > Flask could be a great solution to keep the whole framework running. > (already made it work on Galaxy, but we want to keep it ultra-simple and > nice-looking) > > However, does anyone know if Flask could handle an execution of such > command line tool, wait for the tool to finish and send back the user the > generated resulting file ? > > > Best regards, > Piotr > Hi Piotr! Flask doesn't provide a way to do this kind of stuff innately (afaik). Basically, you will have to run your program in a second process, take the results and send them in an http response. However, without knowing how your program works I can't tell you the best way to go about this. I think running the program and leaving the request hanging until it has terminated isn't a good solution. But if you are sure the process will only take a very short time this is probably fine. You could start the process, return an id and fetch the results later with a second request. A solution I think is very nice, is to stream the results back to the client. There is a chapter in the docs abouth this: http://flask.pocoo.org/docs/0.10/patterns/streaming/ Here is a simple but working example that invokes the ping utility and streams it's output back to the client. from shelljob import proc from flask import Flask, Response app = Flask(__name__) @app.route('/') def index(): group = proc.Group() group.run(['ping', '-c', '10', '8.8.8.8']) def generator(): while group.is_pending(): data = group.readlines() for handle, lines in data: yield lines return Response(generator(), mimetype='text/plain') if __name__ == '__main__': app.run(debug=True) The shelljob package uses the subprocess module. You could use that module directly but I think this is more convenient. As you see, it doesn't require much code to do sth like this. Also: You probably want to let your users set some arguments to your program through the web interface. So don't forget to sanitize your inputs! I hope this was of any help David From jicenhower at yahoo.com Wed Sep 23 16:17:02 2015 From: jicenhower at yahoo.com (Jim Icenhower) Date: Wed, 23 Sep 2015 14:17:02 +0000 (UTC) Subject: [Flask] PyExcel with Flask, updating a record Message-ID: <806602680.276170.1443017822237.JavaMail.yahoo@mail.yahoo.com> Hi,I'm trying to use pyexcel to import a spreadsheet but I don't want to add existing records to the table. I'd either like to skip them or, preferably, update them.I'm currently using the?save_book_to_database() method with an init function. I'd love to be able to return None from the init function and have save_book_to_database() skip the record but that doesn't seem to be working. Do I just need to hand code record inserts and updates or is there a library to handle that more elegantly? Any help will be greatly appreciated! Here's a snippet: @app.route("/importEvents", methods=['GET', 'POST']) def doEventsImport(): if request.method == 'POST': def init_func(row): # see if this is an existing event eventKey = row["EventKey"] foundEvent = db.session.query(Event).filter_by(EventKey=row['EventKey']).first() if foundEvent: print 'foundEvent:' print foundEvent return None event = Event(row['EventKey'], row['Name'], row['Description'], row['BeginDate'], row['EndDate'], row['RegBeginDate'], row['RegEndDate'], row['Location'], row['Address1'], row['Address2'], row['City'], row['State'], row['Zip'], row['URL'], row['Email'], row['Phone']) return event request.save_book_to_database(field_name='file', session=db.session, tables=[Event], initializers=[(init_func)]) return "Saved" ?Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From kajocina at gmail.com Thu Sep 24 15:04:36 2015 From: kajocina at gmail.com (Piotr Grabowski) Date: Thu, 24 Sep 2015 15:04:36 +0200 Subject: [Flask] Flask execute system command / wait / return result ? In-Reply-To: <5601DFC4.5030308@gmx.de> References: <5601DFC4.5030308@gmx.de> Message-ID: Hello again Dear People, after getting some helpful responses and doing online research, I concluded that a combination of Celery and Redis will help me create the scheduling/resource managing pipeline for running the tools by the online users. However, I am still a little uncertain about one part of the solution. When the tools finishes work, it creates output files (3 of them, could be zipped into 1 though). How do I route back those files uniquely to the user ? The web app will be asking for email and the idea is to just send back download URLs to given users that their work is finished. However, I have no idea how to set it up. Do you have any ideas where to look ? The tool works from the command line so a user clicks submit on the page -> the job gets added to Redis by Flask -> Celery takes it and throws at an idle worker -> the script finishes with files generated... and what then ? Any advice is appreciated! Best regards, Piotr On Wed, Sep 23, 2015 at 1:09 AM, David Nieder wrote: > On 22.09.2015 18:38, Piotr Grabowski wrote: > >> Hi! >> >> I am in a phase of planning a web application for my group (academic >> research) and would love to get some advice or input from more advanced >> Flask users/devs. >> >> We developed a bioinformatics tool that we run from a command line, it's >> run simply as ./tool_binary , so pretty standard >> stuff. >> >> We also are trying to turn this into an extremely easy-to-use tool for >> biologists and are looking for a proper online framework. We decided that >> Flask could be a great solution to keep the whole framework running. >> (already made it work on Galaxy, but we want to keep it ultra-simple and >> nice-looking) >> >> However, does anyone know if Flask could handle an execution of such >> command line tool, wait for the tool to finish and send back the user the >> generated resulting file ? >> >> >> Best regards, >> Piotr >> >> > Hi Piotr! > > Flask doesn't provide a way to do this kind of stuff innately (afaik). > Basically, you will have to run your program in a second process, take > the results and send them in an http response. However, without knowing > how your program works I can't tell you the best way to go about this. > > I think running the program and leaving the request hanging until it has > terminated isn't a good solution. But if you are sure the process will > only take a very short time this is probably fine. > > You could start the process, return an id and fetch the results later > with a second request. > > A solution I think is very nice, is to stream the results back to the > client. There is a chapter in the docs abouth this: > http://flask.pocoo.org/docs/0.10/patterns/streaming/ > > Here is a simple but working example that invokes the ping utility and > streams it's output back to the client. > > > from shelljob import proc > from flask import Flask, Response > > app = Flask(__name__) > > @app.route('/') > def index(): > group = proc.Group() > group.run(['ping', '-c', '10', '8.8.8.8']) > > def generator(): > while group.is_pending(): > data = group.readlines() > for handle, lines in data: > yield lines > > return Response(generator(), mimetype='text/plain') > > > if __name__ == '__main__': > app.run(debug=True) > > > The shelljob package uses the subprocess module. You could use that > module directly but I think this is more convenient. As you see, it > doesn't require much code to do sth like this. > > Also: You probably want to let your users set some arguments to your > program through the web interface. So don't forget to sanitize your > inputs! > > I hope this was of any help > David > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at davidbaumgold.com Thu Sep 24 15:28:21 2015 From: david at davidbaumgold.com (David Baumgold) Date: Thu, 24 Sep 2015 09:28:21 -0400 Subject: [Flask] Flask execute system command / wait / return result ? In-Reply-To: References: <5601DFC4.5030308@gmx.de> Message-ID: When the script has finished generating the files, they?ll need to be put somewhere that is designed to hold and serve static files. Many people use a service like Amazon S3 for this, but if you don?t have many users, or the files aren?t very large, then you could just store them on the filesystem of your server. At any rate, your worker should be able to also send out an email to the user at the end of the task, with a URL to wherever you?re serving the static files from, either a URL to the file(s) on S3, or a URL to your webserver that identifies the file(s) there. If you?re going to be sending email, you may want to have a look at Flask-Mail (https://pythonhosted.org/Flask-Mail/), or use an email service like Amazon SES to send the email on your behalf. Another thing to consider is how sensitive these generated files are. The files are generated by a request from a user, so how bad would it be if someone other than the requestor was able to download these files? If it would be no problem at all, then you can use sensible, guessable URLs. If it would be a problem, then you should include some sort of randomly-generated string in the URL name ? that makes it almost impossible to guess the URL, but the user still won?t have any problem because the email link will contain the randomly-generated string. If it would be a huge, business-destroying problem, then you should implement authentication on the file download so that the user has to prove that they are the same person who requested the file, in order to download it. Authentication for downloads can be a tricky thing to get right due to performance concerns, and it's usually a bad user experience, so be careful how you do it. David Baumgold From:?Piotr Grabowski Reply:?Piotr Grabowski > Date:?September 24, 2015 at 9:05:11 AM To:? Cc:?flask at python.org > Subject:? Re: [Flask] Flask execute system command / wait / return result ? Hello again Dear People, after getting some helpful responses and doing online research, I concluded that a combination of Celery and Redis will help me create the scheduling/resource managing pipeline for running the tools by the online users. However, I am still a little uncertain about one part of the solution. When the tools finishes work, it creates output files (3 of them, could be zipped into 1 though). How do I route back those files uniquely to the user ? The web app will be asking for email and the idea is to just send back download URLs to given users that their work is finished. However, I have no idea how to set it up. Do you have any ideas where to look ? The tool works from the command line so a user clicks submit on the page -> the job gets added to Redis by Flask -> Celery takes it and throws at an idle worker -> the script finishes with files generated... and what then ? Any advice is appreciated! Best regards, Piotr On Wed, Sep 23, 2015 at 1:09 AM, David Nieder wrote: On 22.09.2015 18:38, Piotr Grabowski wrote: Hi! I am in a phase of planning a web application for my group (academic research) and would love to get some advice or input from more advanced Flask users/devs. We developed a bioinformatics tool that we run from a command line, it's run simply as ./tool_binary , so pretty standard stuff. We also are trying to turn this into an extremely easy-to-use tool for biologists and are looking for a proper online framework. We decided that Flask could be a great solution to keep the whole framework running. (already made it work on Galaxy, but we want to keep it ultra-simple and nice-looking) However, does anyone know if Flask could handle an execution of such command line tool, wait for the tool to finish and send back the user the generated resulting file ? Best regards, Piotr Hi Piotr! Flask doesn't provide a way to do this kind of stuff innately (afaik). Basically, you will have to run your program in a second process, take the results and send them in an http response. However, without knowing how your program works I can't tell you the best way to go about this. I think running the program and leaving the request hanging until it has terminated isn't a good solution. But if you are sure the process will only take a very short time this is probably fine. You could start the process, return an id and fetch the results later with a second request. A solution I think is very nice, is to stream the results back to the client. There is a chapter in the docs abouth this: http://flask.pocoo.org/docs/0.10/patterns/streaming/ Here is a simple but working example that invokes the ping utility and streams it's output back to the client. from shelljob import proc from flask import Flask, Response app = Flask(__name__) @app.route('/') def index(): ? ? group = proc.Group() ? ? group.run(['ping', '-c', '10', '8.8.8.8']) ? ? def generator(): ? ? ? ? while group.is_pending(): ? ? ? ? ? ? data = group.readlines() ? ? ? ? ? ? for handle, lines in data: ? ? ? ? ? ? ? ? yield lines ? ? return Response(generator(), mimetype='text/plain') if __name__ == '__main__': ? ? app.run(debug=True) The shelljob package uses the subprocess module. You could use that module directly but I think this is more convenient. As you see, it doesn't require much code to do sth like this. Also: You probably want to let your users set some arguments to your program through the web interface. So don't forget to sanitize your inputs! I hope this was of any help David _______________________________________________ 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 coreybrett at gmail.com Thu Sep 24 16:59:12 2015 From: coreybrett at gmail.com (Corey Boyle) Date: Thu, 24 Sep 2015 10:59:12 -0400 Subject: [Flask] gunicorn with gevent worker compatibilty Message-ID: I have been running my app with gunicorn/gevent on my dev box. I haven't found any errors after using all of the apps features. Is there anyway to know if all the packages I depend on are "officially" compatible with gevent? I'm using... - - Flask==0.10.1 - Flask-Admin==1.3.0 - Flask-Bootstrap==3.3.5.6 - Flask-Login==0.2.11 - Flask-Mail==0.9.1 - Flask-Migrate==1.5.1 - Flask-Moment==0.5.1 - Flask-SQLAlchemy==2.0 - Flask-SSLify==0.1.5 - Flask-Script==2.0.5 - Flask-Sijax==0.4.1 - Flask-WTF==0.12 - Jinja2==2.8 - Mako==1.0.2 - MarkupSafe==0.23 - SQLAlchemy==1.0.8 - Sijax==0.3.2 - WTForms==2.0.2 - Werkzeug==0.10.4 - alembic==0.8.2 - argparse==1.2.1 - beautifulsoup4==4.4.0 - blinker==1.4 - dominate==2.1.12 - future==0.15.1 - gevent==1.0.2 - greenlet==0.4.9 - gunicorn==19.3.0 - html5lib==0.999999 - httplib2==0.9.1 - itsdangerous==0.24 - lob==2.18 - psycopg2==2.6.1 - python-editor==0.4 - pytz==2015.4 - redis==2.10.3 - requests==2.7.0 - six==1.9.0 - stripe==1.25.0 - twilio==4.5.0 - wsgiref==0.1.2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From coreybrett at gmail.com Thu Sep 24 22:39:32 2015 From: coreybrett at gmail.com (Corey Boyle) Date: Thu, 24 Sep 2015 16:39:32 -0400 Subject: [Flask] Redis max connections Message-ID: When running a Flask app via Gunicorn with gevent, how should I calculate the max connections setting for redispy? I am limited to 30 connections, and I'm running with WEB_CONCURRENCY set to 8. ~Sent from my Nexus 5 -------------- next part -------------- An HTML attachment was scrubbed... URL: From coreybrett at gmail.com Fri Sep 25 15:35:18 2015 From: coreybrett at gmail.com (Corey Boyle) Date: Fri, 25 Sep 2015 09:35:18 -0400 Subject: [Flask] Redis max connections In-Reply-To: References: Message-ID: Just wanted to share this. I found that by creating my Redis client in its own module and importing it as needed, that when gunicorn is started, only one client gets created. I was thinking it would create a client for each worker, but that doesn't seem to be the case. So I think I can set my max connections based on total allowed divided by number of servers. I did this by adding "print ('client id= ',id(client))" inside the redis function that runs the most in my code. The printed ID was always the same. I would to hear from anyone who has dealt with Redis & Flask. On Thu, Sep 24, 2015 at 4:39 PM, Corey Boyle wrote: > When running a Flask app via Gunicorn with gevent, how should I calculate > the max connections setting for redispy? > > I am limited to 30 connections, and I'm running with WEB_CONCURRENCY set > to 8. > > ~Sent from my Nexus 5 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sebastian_cheung at yahoo.com Tue Sep 29 12:51:39 2015 From: sebastian_cheung at yahoo.com (Sebastian Cheung) Date: Tue, 29 Sep 2015 11:51:39 +0100 Subject: [Flask] How to merge two Flask Apps Message-ID: <415E0590-5237-4532-9573-9E6EADEE1212@yahoo.com> I am trying to merge two flask apps, both from Miguel Grinberg's Flask-SocketIO-Chat into another one of his Microblog so that after user login to the main microblog then the other Chat app could be launched if user selects of the options, which in this case is the Chat. I started but tricky when both projects contain a number of files with different dependencies. The idea is learn how to merge different Flask apps as one. Sent from my iPhone From amriabdesslem at gmail.com Tue Sep 29 12:58:36 2015 From: amriabdesslem at gmail.com (Abdesslem Amri) Date: Tue, 29 Sep 2015 11:58:36 +0100 Subject: [Flask] How to merge two Flask Apps In-Reply-To: <415E0590-5237-4532-9573-9E6EADEE1212@yahoo.com> References: <415E0590-5237-4532-9573-9E6EADEE1212@yahoo.com> Message-ID: I think that this link may be helpful http://flask.pocoo.org/docs/0.10/blueprints/ 2015-09-29 11:51 GMT+01:00 Sebastian Cheung via Flask : > I am trying to merge two flask apps, both from Miguel Grinberg's > Flask-SocketIO-Chat into another one of his Microblog so that after user > login to the main microblog then the other Chat app could be launched if > user selects of the options, which in this case is the Chat. > > I started but tricky when both projects contain a number of files with > different dependencies. > > The idea is learn how to merge different Flask apps as one. > > Sent from my iPhone > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sebastian_cheung at yahoo.com Tue Sep 29 13:23:39 2015 From: sebastian_cheung at yahoo.com (Sebastian Cheung) Date: Tue, 29 Sep 2015 12:23:39 +0100 Subject: [Flask] How to merge two Flask Apps In-Reply-To: References: <415E0590-5237-4532-9573-9E6EADEE1212@yahoo.com> Message-ID: <3A7DA4DE-0E35-4A18-A154-DE8A5508E16D@yahoo.com> So blueprint is a must then when combining separate apps together. Sent from my iPhone > On 29 Sep 2015, at 11:58, Abdesslem Amri wrote: > > I think that this link may be helpful http://flask.pocoo.org/docs/0.10/blueprints/ > > 2015-09-29 11:51 GMT+01:00 Sebastian Cheung via Flask : >> I am trying to merge two flask apps, both from Miguel Grinberg's Flask-SocketIO-Chat into another one of his Microblog so that after user login to the main microblog then the other Chat app could be launched if user selects of the options, which in this case is the Chat. >> >> I started but tricky when both projects contain a number of files with different dependencies. >> >> The idea is learn how to merge different Flask apps as one. >> >> Sent from my iPhone >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Wed Sep 30 00:29:48 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Tue, 29 Sep 2015 18:29:48 -0400 Subject: [Flask] (no subject) Message-ID: Hello, everyone. I've been working on web app for a friends restaurant. I am slowly adding the functionality that I need. Earlier today I was able to add a payment method via the Stripe API. I have confirmed that the test payments are going through to my Stripe logs. I followed very closely to the [stripe flask tutorial](https://stripe.com/docs/checkout/guides/flask). Basically I am doing the exact same thing as what is done in the tutorial, except I have adjusted the payment amount based on interaction with the "order online" portion of the website. *First issue:* One issue I am having (which I am sure is just a stupid mistake) is that once the purchase is confirmed, I redirect to a confirmation page to show a summary of the order, but I am getting a "400 Bad Request - CSRF token missing or incorrect" error. I tried to solve the problem using the methods from [this page]( http://flask-wtf.readthedocs.org/en/latest/csrf.html), like adding an empty form with a CSRF token, to no avail. I also tried including a meta tag with the token which also did not work. I am puzzled. A curious thing is that I can access the "payment" page manually via url before and after the transaction goes through. It seems that the trouble only happens when I redirect from the Stripe payment. *Second issue:* Another possibly related issue is that there is a segment of code using the stripe API I have commented out for the following reason. When it is uncommented I get the following error in addition to the CSRF error stated above, "400 Bad Request - The browser (or proxy) sent a request that this server could not understand." If anyone has a chance to take a look at this for me it would be greatly appreciated. Here is the latest version of the project (currently using the meta tag with CSRF). *Project:* https://github.com/callmeskywalker/casa-site *First issue relevant:* stripe import and test keys: https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L38-L43 order view function: https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L47-L128 pass stripe key to 'order' template: https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L128 stripe implementation in 'order' template: https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L50-L64 action to redirect to the 'payment' template (just to display order details): https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L51 payment template with csrf token: https://github.com/callmeskywalker/casa-site/blob/master/app/templates/payment.html#L5 *Second issue relevant:* code from stripe API in payment view function (causing second error): https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L138-L148 Thanks ahead. I look forward to any responses. Best, Kyle -------------- next part -------------- An HTML attachment was scrubbed... URL: From dorian.hoxha at gmail.com Wed Sep 30 15:35:56 2015 From: dorian.hoxha at gmail.com (Dorian Hoxha) Date: Wed, 30 Sep 2015 15:35:56 +0200 Subject: [Flask] (no subject) In-Reply-To: References: Message-ID: ALWAYS check if the field exist in request.form, if it doesn't you will get a 400 request-error. 2 ways to check: if 'field' in request.form if request.form.get('field') On Wed, Sep 30, 2015 at 12:29 AM, Kyle Lawlor wrote: > Hello, everyone. > > I've been working on web app for a friends restaurant. I am slowly adding > the functionality that I need. Earlier today I was able to add a payment > method via the Stripe API. I have confirmed that the test payments are > going through to my Stripe logs. I followed very closely to the [stripe > flask tutorial](https://stripe.com/docs/checkout/guides/flask). Basically > I am doing the exact same thing as what is done in the tutorial, except I > have adjusted the payment amount based on interaction with the "order > online" portion of the website. > > > *First issue:* > > One issue I am having (which I am sure is just a stupid mistake) is that > once the purchase is confirmed, I redirect to a confirmation page to show a > summary of the order, but I am getting a "400 Bad Request - CSRF token > missing or incorrect" error. > > I tried to solve the problem using the methods from [this page]( > http://flask-wtf.readthedocs.org/en/latest/csrf.html), like adding an > empty form with a CSRF token, to no avail. I also tried including a meta > tag with the token which also did not work. > > I am puzzled. A curious thing is that I can access the "payment" page > manually via url before and after the transaction goes through. It seems > that the trouble only happens when I redirect from the Stripe payment. > > *Second issue:* > > Another possibly related issue is that there is a segment of code using > the stripe API I have commented out for the following reason. When it is > uncommented I get the following error in addition to the CSRF error stated > above, "400 Bad Request - The browser (or proxy) sent a request that this > server could not understand." > > If anyone has a chance to take a look at this for me it would be greatly > appreciated. Here is the latest version of the project (currently using the > meta tag with CSRF). > > *Project:* https://github.com/callmeskywalker/casa-site > > > > *First issue relevant:* > stripe import and test keys: > > https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L38-L43 > > order view function: > > https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L47-L128 > > > pass stripe key to 'order' template: > > https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L128 > > stripe implementation in 'order' template: > > https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L50-L64 > > action to redirect to the 'payment' template (just to display order > details): > > https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L51 > > payment template with csrf token: > > https://github.com/callmeskywalker/casa-site/blob/master/app/templates/payment.html#L5 > > *Second issue relevant:* > > code from stripe API in payment view function (causing second error): > > https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L138-L148 > > > Thanks ahead. I look forward to any responses. > > Best, > Kyle > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Wed Sep 30 20:01:36 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Wed, 30 Sep 2015 14:01:36 -0400 Subject: [Flask] (no subject) In-Reply-To: References: Message-ID: Ok. Thanks for the response. I will keep this in mind as I continue to diagnose my problem. Did you spot a place in my code where the field d.n.e.? On Wed, Sep 30, 2015 at 9:35 AM, Dorian Hoxha wrote: > ALWAYS check if the field exist in request.form, if it doesn't you will > get a 400 request-error. > 2 ways to check: > if 'field' in request.form > if request.form.get('field') > > On Wed, Sep 30, 2015 at 12:29 AM, Kyle Lawlor > wrote: > >> Hello, everyone. >> >> I've been working on web app for a friends restaurant. I am slowly adding >> the functionality that I need. Earlier today I was able to add a payment >> method via the Stripe API. I have confirmed that the test payments are >> going through to my Stripe logs. I followed very closely to the [stripe >> flask tutorial](https://stripe.com/docs/checkout/guides/flask). >> Basically I am doing the exact same thing as what is done in the tutorial, >> except I have adjusted the payment amount based on interaction with the >> "order online" portion of the website. >> >> >> *First issue:* >> >> One issue I am having (which I am sure is just a stupid mistake) is that >> once the purchase is confirmed, I redirect to a confirmation page to show a >> summary of the order, but I am getting a "400 Bad Request - CSRF token >> missing or incorrect" error. >> >> I tried to solve the problem using the methods from [this page]( >> http://flask-wtf.readthedocs.org/en/latest/csrf.html), like adding an >> empty form with a CSRF token, to no avail. I also tried including a meta >> tag with the token which also did not work. >> >> I am puzzled. A curious thing is that I can access the "payment" page >> manually via url before and after the transaction goes through. It seems >> that the trouble only happens when I redirect from the Stripe payment. >> >> *Second issue:* >> >> Another possibly related issue is that there is a segment of code using >> the stripe API I have commented out for the following reason. When it is >> uncommented I get the following error in addition to the CSRF error stated >> above, "400 Bad Request - The browser (or proxy) sent a request that this >> server could not understand." >> >> If anyone has a chance to take a look at this for me it would be greatly >> appreciated. Here is the latest version of the project (currently using the >> meta tag with CSRF). >> >> *Project:* https://github.com/callmeskywalker/casa-site >> >> >> >> *First issue relevant:* >> stripe import and test keys: >> >> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L38-L43 >> >> order view function: >> >> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L47-L128 >> >> >> pass stripe key to 'order' template: >> >> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L128 >> >> stripe implementation in 'order' template: >> >> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L50-L64 >> >> action to redirect to the 'payment' template (just to display order >> details): >> >> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L51 >> >> payment template with csrf token: >> >> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/payment.html#L5 >> >> *Second issue relevant:* >> >> code from stripe API in payment view function (causing second error): >> >> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L138-L148 >> >> >> Thanks ahead. I look forward to any responses. >> >> Best, >> Kyle >> >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dorian.hoxha at gmail.com Wed Sep 30 20:34:59 2015 From: dorian.hoxha at gmail.com (Dorian Hoxha) Date: Wed, 30 Sep 2015 20:34:59 +0200 Subject: [Flask] (no subject) In-Reply-To: References: Message-ID: Replace the code like I said and try again if the error persist. I don't know if the fields do(nt) exist in your code, that's why you have to fix them by actually checking. On Wed, Sep 30, 2015 at 8:01 PM, Kyle Lawlor wrote: > Ok. Thanks for the response. I will keep this in mind as I continue to > diagnose my problem. Did you spot a place in my code where the field d.n.e.? > > On Wed, Sep 30, 2015 at 9:35 AM, Dorian Hoxha > wrote: > >> ALWAYS check if the field exist in request.form, if it doesn't you will >> get a 400 request-error. >> 2 ways to check: >> if 'field' in request.form >> if request.form.get('field') >> >> On Wed, Sep 30, 2015 at 12:29 AM, Kyle Lawlor >> wrote: >> >>> Hello, everyone. >>> >>> I've been working on web app for a friends restaurant. I am slowly >>> adding the functionality that I need. Earlier today I was able to add a >>> payment method via the Stripe API. I have confirmed that the test payments >>> are going through to my Stripe logs. I followed very closely to the [stripe >>> flask tutorial](https://stripe.com/docs/checkout/guides/flask). >>> Basically I am doing the exact same thing as what is done in the tutorial, >>> except I have adjusted the payment amount based on interaction with the >>> "order online" portion of the website. >>> >>> >>> *First issue:* >>> >>> One issue I am having (which I am sure is just a stupid mistake) is that >>> once the purchase is confirmed, I redirect to a confirmation page to show a >>> summary of the order, but I am getting a "400 Bad Request - CSRF token >>> missing or incorrect" error. >>> >>> I tried to solve the problem using the methods from [this page]( >>> http://flask-wtf.readthedocs.org/en/latest/csrf.html), like adding an >>> empty form with a CSRF token, to no avail. I also tried including a meta >>> tag with the token which also did not work. >>> >>> I am puzzled. A curious thing is that I can access the "payment" page >>> manually via url before and after the transaction goes through. It seems >>> that the trouble only happens when I redirect from the Stripe payment. >>> >>> *Second issue:* >>> >>> Another possibly related issue is that there is a segment of code using >>> the stripe API I have commented out for the following reason. When it is >>> uncommented I get the following error in addition to the CSRF error stated >>> above, "400 Bad Request - The browser (or proxy) sent a request that this >>> server could not understand." >>> >>> If anyone has a chance to take a look at this for me it would be greatly >>> appreciated. Here is the latest version of the project (currently using the >>> meta tag with CSRF). >>> >>> *Project:* https://github.com/callmeskywalker/casa-site >>> >>> >>> >>> *First issue relevant:* >>> stripe import and test keys: >>> >>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L38-L43 >>> >>> order view function: >>> >>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L47-L128 >>> >>> >>> pass stripe key to 'order' template: >>> >>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L128 >>> >>> stripe implementation in 'order' template: >>> >>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L50-L64 >>> >>> action to redirect to the 'payment' template (just to display order >>> details): >>> >>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L51 >>> >>> payment template with csrf token: >>> >>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/payment.html#L5 >>> >>> *Second issue relevant:* >>> >>> code from stripe API in payment view function (causing second error): >>> >>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L138-L148 >>> >>> >>> Thanks ahead. I look forward to any responses. >>> >>> Best, >>> Kyle >>> >>> >>> _______________________________________________ >>> Flask mailing list >>> Flask at python.org >>> https://mail.python.org/mailman/listinfo/flask >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klawlor419 at gmail.com Wed Sep 30 21:28:23 2015 From: klawlor419 at gmail.com (Kyle Lawlor) Date: Wed, 30 Sep 2015 15:28:23 -0400 Subject: [Flask] (no subject) In-Reply-To: References: Message-ID: Ok, I will look into this first. Thanks again for the pointers. In the meantime, any further comments still appreciated. On Wed, Sep 30, 2015 at 2:34 PM, Dorian Hoxha wrote: > Replace the code like I said and try again if the error persist. > I don't know if the fields do(nt) exist in your code, that's why you have > to fix them by actually checking. > > On Wed, Sep 30, 2015 at 8:01 PM, Kyle Lawlor wrote: > >> Ok. Thanks for the response. I will keep this in mind as I continue to >> diagnose my problem. Did you spot a place in my code where the field d.n.e.? >> >> On Wed, Sep 30, 2015 at 9:35 AM, Dorian Hoxha >> wrote: >> >>> ALWAYS check if the field exist in request.form, if it doesn't you will >>> get a 400 request-error. >>> 2 ways to check: >>> if 'field' in request.form >>> if request.form.get('field') >>> >>> On Wed, Sep 30, 2015 at 12:29 AM, Kyle Lawlor >>> wrote: >>> >>>> Hello, everyone. >>>> >>>> I've been working on web app for a friends restaurant. I am slowly >>>> adding the functionality that I need. Earlier today I was able to add a >>>> payment method via the Stripe API. I have confirmed that the test payments >>>> are going through to my Stripe logs. I followed very closely to the [stripe >>>> flask tutorial](https://stripe.com/docs/checkout/guides/flask). >>>> Basically I am doing the exact same thing as what is done in the tutorial, >>>> except I have adjusted the payment amount based on interaction with the >>>> "order online" portion of the website. >>>> >>>> >>>> *First issue:* >>>> >>>> One issue I am having (which I am sure is just a stupid mistake) is >>>> that once the purchase is confirmed, I redirect to a confirmation page to >>>> show a summary of the order, but I am getting a "400 Bad Request - CSRF >>>> token missing or incorrect" error. >>>> >>>> I tried to solve the problem using the methods from [this page]( >>>> http://flask-wtf.readthedocs.org/en/latest/csrf.html), like adding an >>>> empty form with a CSRF token, to no avail. I also tried including a meta >>>> tag with the token which also did not work. >>>> >>>> I am puzzled. A curious thing is that I can access the "payment" page >>>> manually via url before and after the transaction goes through. It seems >>>> that the trouble only happens when I redirect from the Stripe payment. >>>> >>>> *Second issue:* >>>> >>>> Another possibly related issue is that there is a segment of code using >>>> the stripe API I have commented out for the following reason. When it is >>>> uncommented I get the following error in addition to the CSRF error stated >>>> above, "400 Bad Request - The browser (or proxy) sent a request that this >>>> server could not understand." >>>> >>>> If anyone has a chance to take a look at this for me it would be >>>> greatly appreciated. Here is the latest version of the project (currently >>>> using the meta tag with CSRF). >>>> >>>> *Project:* https://github.com/callmeskywalker/casa-site >>>> >>>> >>>> >>>> *First issue relevant:* >>>> stripe import and test keys: >>>> >>>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L38-L43 >>>> >>>> order view function: >>>> >>>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L47-L128 >>>> >>>> >>>> pass stripe key to 'order' template: >>>> >>>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L128 >>>> >>>> stripe implementation in 'order' template: >>>> >>>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L50-L64 >>>> >>>> action to redirect to the 'payment' template (just to display order >>>> details): >>>> >>>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L51 >>>> >>>> payment template with csrf token: >>>> >>>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/payment.html#L5 >>>> >>>> *Second issue relevant:* >>>> >>>> code from stripe API in payment view function (causing second error): >>>> >>>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L138-L148 >>>> >>>> >>>> Thanks ahead. I look forward to any responses. >>>> >>>> Best, >>>> Kyle >>>> >>>> >>>> _______________________________________________ >>>> Flask mailing list >>>> Flask at python.org >>>> https://mail.python.org/mailman/listinfo/flask >>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dorian.hoxha at gmail.com Wed Sep 30 21:57:06 2015 From: dorian.hoxha at gmail.com (Dorian Hoxha) Date: Wed, 30 Sep 2015 21:57:06 +0200 Subject: [Flask] (no subject) In-Reply-To: References: Message-ID: >From a quick look, don't store config values in the code. Careful with stripe keys (they look like test keys though) I think it's more pythonic: if 'a' not in b instead of : if not 'a' in b: I'm not sure though. On Wed, Sep 30, 2015 at 9:28 PM, Kyle Lawlor wrote: > Ok, I will look into this first. Thanks again for the pointers. In the > meantime, any further comments still appreciated. > > On Wed, Sep 30, 2015 at 2:34 PM, Dorian Hoxha > wrote: > >> Replace the code like I said and try again if the error persist. >> I don't know if the fields do(nt) exist in your code, that's why you have >> to fix them by actually checking. >> >> On Wed, Sep 30, 2015 at 8:01 PM, Kyle Lawlor >> wrote: >> >>> Ok. Thanks for the response. I will keep this in mind as I continue to >>> diagnose my problem. Did you spot a place in my code where the field d.n.e.? >>> >>> On Wed, Sep 30, 2015 at 9:35 AM, Dorian Hoxha >>> wrote: >>> >>>> ALWAYS check if the field exist in request.form, if it doesn't you will >>>> get a 400 request-error. >>>> 2 ways to check: >>>> if 'field' in request.form >>>> if request.form.get('field') >>>> >>>> On Wed, Sep 30, 2015 at 12:29 AM, Kyle Lawlor >>>> wrote: >>>> >>>>> Hello, everyone. >>>>> >>>>> I've been working on web app for a friends restaurant. I am slowly >>>>> adding the functionality that I need. Earlier today I was able to add a >>>>> payment method via the Stripe API. I have confirmed that the test payments >>>>> are going through to my Stripe logs. I followed very closely to the [stripe >>>>> flask tutorial](https://stripe.com/docs/checkout/guides/flask). >>>>> Basically I am doing the exact same thing as what is done in the tutorial, >>>>> except I have adjusted the payment amount based on interaction with the >>>>> "order online" portion of the website. >>>>> >>>>> >>>>> *First issue:* >>>>> >>>>> One issue I am having (which I am sure is just a stupid mistake) is >>>>> that once the purchase is confirmed, I redirect to a confirmation page to >>>>> show a summary of the order, but I am getting a "400 Bad Request - CSRF >>>>> token missing or incorrect" error. >>>>> >>>>> I tried to solve the problem using the methods from [this page]( >>>>> http://flask-wtf.readthedocs.org/en/latest/csrf.html), like adding an >>>>> empty form with a CSRF token, to no avail. I also tried including a meta >>>>> tag with the token which also did not work. >>>>> >>>>> I am puzzled. A curious thing is that I can access the "payment" page >>>>> manually via url before and after the transaction goes through. It seems >>>>> that the trouble only happens when I redirect from the Stripe payment. >>>>> >>>>> *Second issue:* >>>>> >>>>> Another possibly related issue is that there is a segment of code >>>>> using the stripe API I have commented out for the following reason. When it >>>>> is uncommented I get the following error in addition to the CSRF error >>>>> stated above, "400 Bad Request - The browser (or proxy) sent a request that >>>>> this server could not understand." >>>>> >>>>> If anyone has a chance to take a look at this for me it would be >>>>> greatly appreciated. Here is the latest version of the project (currently >>>>> using the meta tag with CSRF). >>>>> >>>>> *Project:* https://github.com/callmeskywalker/casa-site >>>>> >>>>> >>>>> >>>>> *First issue relevant:* >>>>> stripe import and test keys: >>>>> >>>>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L38-L43 >>>>> >>>>> order view function: >>>>> >>>>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L47-L128 >>>>> >>>>> >>>>> pass stripe key to 'order' template: >>>>> >>>>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L128 >>>>> >>>>> stripe implementation in 'order' template: >>>>> >>>>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L50-L64 >>>>> >>>>> action to redirect to the 'payment' template (just to display order >>>>> details): >>>>> >>>>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/order.html#L51 >>>>> >>>>> payment template with csrf token: >>>>> >>>>> https://github.com/callmeskywalker/casa-site/blob/master/app/templates/payment.html#L5 >>>>> >>>>> *Second issue relevant:* >>>>> >>>>> code from stripe API in payment view function (causing second error): >>>>> >>>>> https://github.com/callmeskywalker/casa-site/blob/master/app/main/views.py#L138-L148 >>>>> >>>>> >>>>> Thanks ahead. I look forward to any responses. >>>>> >>>>> Best, >>>>> Kyle >>>>> >>>>> >>>>> _______________________________________________ >>>>> Flask mailing list >>>>> Flask at python.org >>>>> https://mail.python.org/mailman/listinfo/flask >>>>> >>>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: