From andreas.dorfner at stud.hs-regensburg.de Sun Dec 4 15:17:30 2016 From: andreas.dorfner at stud.hs-regensburg.de (Andreas Dorfner) Date: Sun, 4 Dec 2016 21:17:30 +0100 Subject: [Flask] Read data from existing database Message-ID: <981637e0-ea83-df32-54cc-fc49744bb95a@stud.hs-regensburg.de> Hello everyone, I've created a data-logger using Flask-SQLAlchemy with the following schematic/models: class Phase1 with id, Urms, Irms, Prms, Qrms, cosphi class Phase2 with id, Urms, Irms, Prms, Qrms, cosphi class Phase3 with id, Urms, Irms, Prms, Qrms, cosphi class PhaseTotal with id, Prms, Qrms Attached you can find the resultant database created by the file logger_sqlalchemy.py. In the second part of the project I would like to set up a webserver to display the newest database-data on a website. Because there is an infinite loop in the logger file, another python file (webserver.py, also attached) is used to do so. Like described on the website "http://flask-sqlalchemy.pocoo.org/dev/queries/#querying-records", the following lines should display the Urms value with id 5 on the screen (logger_sqlalchemy.py doesn't run at this time): URMS_L1 = Phase1.query.filter_by(id=5).first() print(URMS_L1.Urms) But there is always an error "Phase1 is not defined"! Does anybody know what's going wrong? To link the file to the corresponding database, the following lines are used: app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////root/project/logger_sqlalchemy.db' db = SQLAlchemy(app) Maybe the link to the database is not correct? The database is in the same folder than the webserver file. Many thanks, Andreas --- Diese E-Mail wurde von Avast Antivirus-Software auf Viren gepr?ft. https://www.avast.com/antivirus -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- #all the imports import time from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////root/project/logger_sqlalchemy.db' db = SQLAlchemy(app) #--------------------------------------------------------------------------- #connects to the specific database #def connect_db(): # return sqlite3.connect(app.config['DATABASE']) #--------------------------------------------------------------------------- URMS_L1 = Phase1.query.filter_by(id=5).first() print(URMS_L1.Urms) #--------------------------------------------------------------------------- #That function pass the entries as dicts to the show_entries.html template #and return the broadcasted one. #@app.route('/') #@app.route('/user/') #def show_user(username): # user = User.query.filter_by(username=username).first_or_404() # return render_template('show_user.html', user=user) #--------------------------------------------------------------------------- #Run the file as a standalone application on IP address 192.168.7.2 (BBB) #at Port 5000 #if __name__ == '__main__': # app.run(host = '192.168.7.2') #--------------------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: logger_sqlalchemy.db Type: application/octet-stream Size: 5120 bytes Desc: not available URL: From aresowj at gmail.com Mon Dec 5 00:54:37 2016 From: aresowj at gmail.com (Ares Ou) Date: Sun, 4 Dec 2016 21:54:37 -0800 Subject: [Flask] Read data from existing database In-Reply-To: <981637e0-ea83-df32-54cc-fc49744bb95a@stud.hs-regensburg.de> References: <981637e0-ea83-df32-54cc-fc49744bb95a@stud.hs-regensburg.de> Message-ID: Hi Andreas, You have to import Phrase1 from the file you define it. For example: from .models import Phrase1, Phrase2 Best regards, Ares Ou *Software Engineer / Full-Stack Python Developer* *Blog:* http://aresou.net | *Github:* https://github.com/aresowj *Stack Overflow:* http://stackoverflow.com/users/5183727/ares-ou Ares Ou On Sun, Dec 4, 2016 at 12:17 PM, Andreas Dorfner < andreas.dorfner at stud.hs-regensburg.de> wrote: > Hello everyone, > > I've created a data-logger using Flask-SQLAlchemy with the following > schematic/models: > > class Phase1 with id, Urms, Irms, Prms, Qrms, cosphi > class Phase2 with id, Urms, Irms, Prms, Qrms, cosphi > class Phase3 with id, Urms, Irms, Prms, Qrms, cosphi > class PhaseTotal with id, Prms, Qrms > > Attached you can find the resultant database created by the file > logger_sqlalchemy.py. > > In the second part of the project I would like to set up a webserver to > display the newest database-data on a website. > Because there is an infinite loop in the logger file, another python file > (webserver.py, also attached) is used to do so. > > Like described on the website "http://flask-sqlalchemy. > pocoo.org/dev/queries/#querying-records" > , the > following lines should display the Urms value with id 5 on the screen > (logger_sqlalchemy.py doesn't run at this time): > > URMS_L1 = Phase1.query.filter_by(id=5).first() > print(URMS_L1.Urms) > > But there is always an error "Phase1 is not defined"! > Does anybody know what's going wrong? > > To link the file to the corresponding database, the following lines are > used: > > app = Flask(__name__) > app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////root/project/logger_sqlalchemy.db' > > db = SQLAlchemy(app) > > Maybe the link to the database is not correct? The database is in the same > folder than the webserver file. > > Many thanks, > Andreas > > > Virenfrei. > www.avast.com > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From per.laas at sprakochfolkminnen.se Thu Dec 8 09:42:26 2016 From: per.laas at sprakochfolkminnen.se (=?iso-8859-1?Q?Per_L=E5=E5s?=) Date: Thu, 8 Dec 2016 14:42:26 +0000 Subject: [Flask] Access to /static (static files) when deployed with cgi Message-ID: <4BD1D479D41CBD4AA40C77701B431C964FE2AE@COLUMBA02.user.uu.se> Hi! I am new to flask and have deployed a flask web application based on a flask demo-project with cgi: ScriptAlias /flaskutforskning /path/flaskutforskning/flaskutforskning.cgi in production on the linux server, deployed following instructions at http://flask.pocoo.org/docs/0.11/deploying/cgi/. Se also file tree below. I run the development-server in Visual Studio in my PC using from runserver.py, created by the VS Python tools - Flask web project, which I guess uses WSGI. See screen images below. The application works fine except the links to static-files are different in development in Visual Studio and in production on the linux server. See file hierarchy below. Development-server in Visual Studio in my PC http://localhost:PORT/static/scripts/SPAshowresult.js In production server: http://www.mydomain.com/flaskutforskning/flaskutforskning/static/scripts/SPAshowresult.js Questions: ? Does anybody have a suggestion how to find a better way to work with paths so there is the same static path in dev and production? ? Is there a better IDE than Visual Studio for development and debugging in the code, step by step? Thank you so much in advance. Best regards, Per L??s [cid:image002.jpg at 01D25169.ACDFA6C0] [cid:image004.jpg at 01D25169.ACDFA6C0] . --- flaskutforskning -- - --- __init__.py -- - --- static -- - -- - --- content -- - -- - -- - --- bootstrap.css -- - -- - -- - --- bootstrap.min.css -- - -- - -- - --- site.css -- - -- - --- fonts -- - -- - -- - --- glyphicons-halflings-regular.eot -- - -- - -- - --- glyphicons-halflings-regular.svg -- - -- - -- - --- glyphicons-halflings-regular.ttf -- - -- - -- - --- glyphicons-halflings-regular.woff -- - -- - --- scripts -- - -- - --- autocomplete.js -- - -- - --- bootstrap.js -- - -- - --- bootstrap.min.js -- - -- - --- jquery-1.10.2.intellisense.js -- - -- - --- jquery-1.10.2.js -- - -- - --- jquery-1.10.2.min.js -- - -- - --- jquery-1.10.2.min.map -- - -- - --- jquery.validate.js -- - -- - --- jquery.validate.min.js -- - -- - --- jquery.validate.unobtrusive.js -- - -- - --- jquery.validate.unobtrusive.min.js -- - -- - --- jquery.validate-vsdoc.js -- - -- - --- modernizr-2.6.2.js -- - -- - --- _references.js -- - -- - --- respond.js -- - -- - --- respond.min.js -- - -- - --- SPAshowresult.js -- - --- templates -- - -- - --- about.html -- - -- - --- contact.html -- - -- - --- dynfragasr.html -- - -- - --- dynfrageladan - Copy.html -- - -- - --- dynfrageladan.html -- - -- - --- extendslayout.html -- - -- - --- fragasr.html -- - -- - --- frageladan - Copy (2).html -- - -- - --- frageladan - Copy.html -- - -- - --- frageladan.html -- - -- - --- frageladan_origSPA.html -- - -- - --- index.html -- - -- - --- layout.html -- - -- - --- test.html -- - --- utils.py -- - --- views.py -- - --- views - test.py --- flaskutforskning.cgi --- svnupdate.log --- svnupdate.sh 6 directories, 45 files -- Per L??s Developer Institutet f?r spr?k och folkminnen www.sprakochfolkminnen.se +46 18 652 446 per.laas at sprakochfolkminnen.se -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image002.jpg Type: image/jpeg Size: 18942 bytes Desc: image002.jpg URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image004.jpg Type: image/jpeg Size: 27491 bytes Desc: image004.jpg URL: From christopher.xs.zee at gmail.com Thu Dec 8 10:58:08 2016 From: christopher.xs.zee at gmail.com (Christopher Zee) Date: Thu, 8 Dec 2016 16:58:08 +0100 Subject: [Flask] Access to /static (static files) when deployed with cgi In-Reply-To: <4BD1D479D41CBD4AA40C77701B431C964FE2AE@COLUMBA02.user.uu.se> References: <4BD1D479D41CBD4AA40C77701B431C964FE2AE@COLUMBA02.user.uu.se> Message-ID: Hi, You should preferably make the front-end use 'static/' in any hard-coded links. This way Flask will serve up the appropriate files. As for the IDE you may look into PyCharm and see if it suits you. -- Christopher On 8 December 2016 at 15:42, Per L??s wrote: > Hi! > > > > I am new to flask and have deployed a flask web application based on a > flask demo-project with cgi: ScriptAlias /flaskutforskning > /path/flaskutforskning/flaskutforskning.cgi in production on the linux > server, deployed following instructions at http://flask.pocoo.org/docs/0. > 11/deploying/cgi/. Se also file tree below. > > > > I run the development-server in Visual Studio in my PC using from > runserver.py, created by the VS Python tools ? Flask web project, which I > guess uses WSGI. See screen images below. > > > > The application works fine except the links to static-files are different > in development in Visual Studio and in production on the linux server. See > file hierarchy below. > > > > Development-server in Visual Studio in my PC > > http://localhost:PORT/static/scripts/SPAshowresult.js > > > > In production server: > > http://www.mydomain.com/flaskutforskning/flaskutforskning/static/ > scripts/SPAshowresult.js > > > > Questions: > > ? Does anybody have a suggestion how to find a better way to work > with paths so there is the same static path in dev and production? > > ? Is there a better IDE than Visual Studio for development and > debugging in the code, step by step? > > > > Thank you so much in advance. > > > > Best regards, > > > > Per L??s > > > > . > > --- flaskutforskning > > -- - --- __init__.py > > -- - --- static > > -- - -- - --- content > > -- - -- - -- - --- bootstrap.css > > -- - -- - -- - --- bootstrap.min.css > > -- - -- - -- - --- site.css > > -- - -- - --- fonts > > -- - -- - -- - --- glyphicons-halflings-regular.eot > > -- - -- - -- - --- glyphicons-halflings-regular.svg > > -- - -- - -- - --- glyphicons-halflings-regular.ttf > > -- - -- - -- - --- glyphicons-halflings-regular.woff > > -- - -- - --- scripts > > -- - -- - --- autocomplete.js > > -- - -- - --- bootstrap.js > > -- - -- - --- bootstrap.min.js > > -- - -- - --- jquery-1.10.2.intellisense.js > > -- - -- - --- jquery-1.10.2.js > > -- - -- - --- jquery-1.10.2.min.js > > -- - -- - --- jquery-1.10.2.min.map > > -- - -- - --- jquery.validate.js > > -- - -- - --- jquery.validate.min.js > > -- - -- - --- jquery.validate.unobtrusive.js > > -- - -- - --- jquery.validate.unobtrusive.min.js > > -- - -- - --- jquery.validate-vsdoc.js > > -- - -- - --- modernizr-2.6.2.js > > -- - -- - --- _references.js > > -- - -- - --- respond.js > > -- - -- - --- respond.min.js > > -- - -- - --- SPAshowresult.js > > -- - --- templates > > -- - -- - --- about.html > > -- - -- - --- contact.html > > -- - -- - --- dynfragasr.html > > -- - -- - --- dynfrageladan - Copy.html > > -- - -- - --- dynfrageladan.html > > -- - -- - --- extendslayout.html > > -- - -- - --- fragasr.html > > -- - -- - --- frageladan - Copy (2).html > > -- - -- - --- frageladan - Copy.html > > -- - -- - --- frageladan.html > > -- - -- - --- frageladan_origSPA.html > > -- - -- - --- index.html > > -- - -- - --- layout.html > > -- - -- - --- test.html > > -- - --- utils.py > > -- - --- views.py > > -- - --- views - test.py > > --- flaskutforskning.cgi > > --- svnupdate.log > > --- svnupdate.sh > > > > 6 directories, 45 files > > > > > > -- > > Per L??s > > Developer > > Institutet f?r spr?k och folkminnen > > www.sprakochfolkminnen.se > > > > +46 18 652 446 > > per.laas at sprakochfolkminnen.se > > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image004.jpg Type: image/jpeg Size: 27491 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image002.jpg Type: image/jpeg Size: 18942 bytes Desc: not available URL: From spenceryoung at ufl.edu Thu Dec 8 10:16:16 2016 From: spenceryoung at ufl.edu (Young,Spencer P) Date: Thu, 8 Dec 2016 15:16:16 +0000 Subject: [Flask] Access to /static (static files) when deployed with cgi In-Reply-To: <4BD1D479D41CBD4AA40C77701B431C964FE2AE@COLUMBA02.user.uu.se> References: <4BD1D479D41CBD4AA40C77701B431C964FE2AE@COLUMBA02.user.uu.se> Message-ID: <81ba3f5ef8534a8e94016e578f4f0e50@exmbxprd19.ad.ufl.edu> Hi there! What I believe you're looking for is the `static_url_path` argument to the application object. See: http://flask.pocoo.org/docs/0.11/api/#application-object You could store this value in an environment variable or config file on your development and production system so it does not require a code change between your production and development server. Is the app behind a proxy (IE running on localhost or some remote machine) ? If so, you might be looking for is the ProxyFix middleware. http://werkzeug.pocoo.org/docs/0.11/contrib/fixers/#werkzeug.contrib.fixers.ProxyFix Does that help you? Cheers, -Spencer From: Flask [mailto:flask-bounces+spenceryoung=ufl.edu at python.org] On Behalf Of Per L??s Sent: Thursday, December 08, 2016 9:42 AM To: flask at python.org Subject: [Flask] Access to /static (static files) when deployed with cgi Hi! I am new to flask and have deployed a flask web application based on a flask demo-project with cgi: ScriptAlias /flaskutforskning /path/flaskutforskning/flaskutforskning.cgi in production on the linux server, deployed following instructions at http://flask.pocoo.org/docs/0.11/deploying/cgi/. Se also file tree below. I run the development-server in Visual Studio in my PC using from runserver.py, created by the VS Python tools - Flask web project, which I guess uses WSGI. See screen images below. The application works fine except the links to static-files are different in development in Visual Studio and in production on the linux server. See file hierarchy below. Development-server in Visual Studio in my PC http://localhost:PORT/static/scripts/SPAshowresult.js In production server: http://www.mydomain.com/flaskutforskning/flaskutforskning/static/scripts/SPAshowresult.js Questions: ? Does anybody have a suggestion how to find a better way to work with paths so there is the same static path in dev and production? ? Is there a better IDE than Visual Studio for development and debugging in the code, step by step? Thank you so much in advance. Best regards, Per L??s [cid:image001.jpg at 01D2513B.84FA6B50] [cid:image002.jpg at 01D2513B.84FA6B50] . --- flaskutforskning -- - --- __init__.py -- - --- static -- - -- - --- content -- - -- - -- - --- bootstrap.css -- - -- - -- - --- bootstrap.min.css -- - -- - -- - --- site.css -- - -- - --- fonts -- - -- - -- - --- glyphicons-halflings-regular.eot -- - -- - -- - --- glyphicons-halflings-regular.svg -- - -- - -- - --- glyphicons-halflings-regular.ttf -- - -- - -- - --- glyphicons-halflings-regular.woff -- - -- - --- scripts -- - -- - --- autocomplete.js -- - -- - --- bootstrap.js -- - -- - --- bootstrap.min.js -- - -- - --- jquery-1.10.2.intellisense.js -- - -- - --- jquery-1.10.2.js -- - -- - --- jquery-1.10.2.min.js -- - -- - --- jquery-1.10.2.min.map -- - -- - --- jquery.validate.js -- - -- - --- jquery.validate.min.js -- - -- - --- jquery.validate.unobtrusive.js -- - -- - --- jquery.validate.unobtrusive.min.js -- - -- - --- jquery.validate-vsdoc.js -- - -- - --- modernizr-2.6.2.js -- - -- - --- _references.js -- - -- - --- respond.js -- - -- - --- respond.min.js -- - -- - --- SPAshowresult.js -- - --- templates -- - -- - --- about.html -- - -- - --- contact.html -- - -- - --- dynfragasr.html -- - -- - --- dynfrageladan - Copy.html -- - -- - --- dynfrageladan.html -- - -- - --- extendslayout.html -- - -- - --- fragasr.html -- - -- - --- frageladan - Copy (2).html -- - -- - --- frageladan - Copy.html -- - -- - --- frageladan.html -- - -- - --- frageladan_origSPA.html -- - -- - --- index.html -- - -- - --- layout.html -- - -- - --- test.html -- - --- utils.py -- - --- views.py -- - --- views - test.py --- flaskutforskning.cgi --- svnupdate.log --- svnupdate.sh 6 directories, 45 files -- Per L??s Developer Institutet f?r spr?k och folkminnen www.sprakochfolkminnen.se +46 18 652 446 per.laas at sprakochfolkminnen.se -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 18942 bytes Desc: image001.jpg URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image002.jpg Type: image/jpeg Size: 27491 bytes Desc: image002.jpg URL: From per.laas at sprakochfolkminnen.se Fri Dec 9 10:23:25 2016 From: per.laas at sprakochfolkminnen.se (=?iso-8859-1?Q?Per_L=E5=E5s?=) Date: Fri, 9 Dec 2016 15:23:25 +0000 Subject: [Flask] Access to /static (static files) when deployed with cgi In-Reply-To: <81ba3f5ef8534a8e94016e578f4f0e50@exmbxprd19.ad.ufl.edu> References: <4BD1D479D41CBD4AA40C77701B431C964FE2AE@COLUMBA02.user.uu.se> <81ba3f5ef8534a8e94016e578f4f0e50@exmbxprd19.ad.ufl.edu> Message-ID: <4BD1D479D41CBD4AA40C77701B431C96051E0D77@COLUMBA02.user.uu.se> Thanks for your answer! I will try it. Follow up questions: ? For me it is not fully clear if the paths are relative or absolute paths. I guess they are relative. I also wonder what they are relative to: maybe the folder for __init__.py and cgi-file (py-file) in /flaskutforskning or the sub folder for the view.py file in /flaskutforskning/flaskutforskning? See http://flask.pocoo.org/docs/0.11/deploying/cgi/. ? If you have any example of the parameters and how to set them from a config file I would appreciate it a lot. Best regards, Per From: Young,Spencer P [mailto:spenceryoung at ufl.edu] Sent: den 8 december 2016 16:16 To: Per L??s ; flask at python.org Subject: RE: Access to /static (static files) when deployed with cgi Hi there! What I believe you're looking for is the `static_url_path` argument to the application object. See: http://flask.pocoo.org/docs/0.11/api/#application-object You could store this value in an environment variable or config file on your development and production system so it does not require a code change between your production and development server. Is the app behind a proxy (IE running on localhost or some remote machine) ? If so, you might be looking for is the ProxyFix middleware. http://werkzeug.pocoo.org/docs/0.11/contrib/fixers/#werkzeug.contrib.fixers.ProxyFix Does that help you? Cheers, -Spencer From: Flask [mailto:flask-bounces+spenceryoung=ufl.edu at python.org] On Behalf Of Per L??s Sent: Thursday, December 08, 2016 9:42 AM To: flask at python.org Subject: [Flask] Access to /static (static files) when deployed with cgi Hi! I am new to flask and have deployed a flask web application based on a flask demo-project with cgi: ScriptAlias /flaskutforskning /path/flaskutforskning/flaskutforskning.cgi in production on the linux server, deployed following instructions at http://flask.pocoo.org/docs/0.11/deploying/cgi/. Se also file tree below. I run the development-server in Visual Studio in my PC using from runserver.py, created by the VS Python tools - Flask web project, which I guess uses WSGI. See screen images below. The application works fine except the links to static-files are different in development in Visual Studio and in production on the linux server. See file hierarchy below. Development-server in Visual Studio in my PC http://localhost:PORT/static/scripts/SPAshowresult.js In production server: http://www.mydomain.com/flaskutforskning/flaskutforskning/static/scripts/SPAshowresult.js Questions: ? Does anybody have a suggestion how to find a better way to work with paths so there is the same static path in dev and production? ? Is there a better IDE than Visual Studio for development and debugging in the code, step by step? Thank you so much in advance. Best regards, Per L??s [cid:image001.jpg at 01D25237.714BAEF0] [cid:image002.jpg at 01D25237.714BAEF0] . --- flaskutforskning -- - --- __init__.py -- - --- static -- - -- - --- content -- - -- - -- - --- bootstrap.css -- - -- - -- - --- bootstrap.min.css -- - -- - -- - --- site.css -- - -- - --- fonts -- - -- - -- - --- glyphicons-halflings-regular.eot -- - -- - -- - --- glyphicons-halflings-regular.svg -- - -- - -- - --- glyphicons-halflings-regular.ttf -- - -- - -- - --- glyphicons-halflings-regular.woff -- - -- - --- scripts -- - -- - --- autocomplete.js -- - -- - --- bootstrap.js -- - -- - --- bootstrap.min.js -- - -- - --- jquery-1.10.2.intellisense.js -- - -- - --- jquery-1.10.2.js -- - -- - --- jquery-1.10.2.min.js -- - -- - --- jquery-1.10.2.min.map -- - -- - --- jquery.validate.js -- - -- - --- jquery.validate.min.js -- - -- - --- jquery.validate.unobtrusive.js -- - -- - --- jquery.validate.unobtrusive.min.js -- - -- - --- jquery.validate-vsdoc.js -- - -- - --- modernizr-2.6.2.js -- - -- - --- _references.js -- - -- - --- respond.js -- - -- - --- respond.min.js -- - -- - --- SPAshowresult.js -- - --- templates -- - -- - --- about.html -- - -- - --- contact.html -- - -- - --- dynfragasr.html -- - -- - --- dynfrageladan - Copy.html -- - -- - --- dynfrageladan.html -- - -- - --- extendslayout.html -- - -- - --- fragasr.html -- - -- - --- frageladan - Copy (2).html -- - -- - --- frageladan - Copy.html -- - -- - --- frageladan.html -- - -- - --- frageladan_origSPA.html -- - -- - --- index.html -- - -- - --- layout.html -- - -- - --- test.html -- - --- utils.py -- - --- views.py -- - --- views - test.py --- flaskutforskning.cgi --- svnupdate.log --- svnupdate.sh 6 directories, 45 files -- Per L??s Developer Institutet f?r spr?k och folkminnen www.sprakochfolkminnen.se +46 18 652 446 per.laas at sprakochfolkminnen.se -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 18942 bytes Desc: image001.jpg URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image002.jpg Type: image/jpeg Size: 27491 bytes Desc: image002.jpg URL: From spenceryoung at UFL.EDU Fri Dec 9 11:15:04 2016 From: spenceryoung at UFL.EDU (Young,Spencer P) Date: Fri, 9 Dec 2016 16:15:04 +0000 Subject: [Flask] Access to /static (static files) when deployed with cgi In-Reply-To: <4BD1D479D41CBD4AA40C77701B431C96051E0D77@COLUMBA02.user.uu.se> References: <4BD1D479D41CBD4AA40C77701B431C964FE2AE@COLUMBA02.user.uu.se> <81ba3f5ef8534a8e94016e578f4f0e50@exmbxprd19.ad.ufl.edu>, <4BD1D479D41CBD4AA40C77701B431C96051E0D77@COLUMBA02.user.uu.se> Message-ID: <595010A8-04BA-47E4-8249-E7FA74CB3715@ufl.edu> There's also a CGI middleware fixer that helps handle issues introduced by CGI paths. http://werkzeug.pocoo.org/docs/0.11/contrib/fixers/ That may be what you're looking for. I believe Flask will otherwise assume that it is the root and your links generated, such as by url_for, are root-relative by default. But if your app is not actually in the root, you run into the issue you first described. There are a few ways of handling the problem, but I think the middleware fixers and configuration changes are ideal, compared to altering a lot of code to deal with the problem so you can keep your Dev and production roughly equal. -Spencer Sent from my iPhone On Dec 9, 2016, at 10:24 AM, Per L??s > wrote: Thanks for your answer! I will try it. Follow up questions: ? For me it is not fully clear if the paths are relative or absolute paths. I guess they are relative. I also wonder what they are relative to: maybe the folder for __init__.py and cgi-file (py-file) in /flaskutforskning or the sub folder for the view.py file in /flaskutforskning/flaskutforskning? See http://flask.pocoo.org/docs/0.11/deploying/cgi/. ? If you have any example of the parameters and how to set them from a config file I would appreciate it a lot. Best regards, Per From: Young,Spencer P [mailto:spenceryoung at ufl.edu] Sent: den 8 december 2016 16:16 To: Per L??s >; flask at python.org Subject: RE: Access to /static (static files) when deployed with cgi Hi there! What I believe you?re looking for is the `static_url_path` argument to the application object. See: http://flask.pocoo.org/docs/0.11/api/#application-object You could store this value in an environment variable or config file on your development and production system so it does not require a code change between your production and development server. Is the app behind a proxy (IE running on localhost or some remote machine) ? If so, you might be looking for is the ProxyFix middleware. http://werkzeug.pocoo.org/docs/0.11/contrib/fixers/#werkzeug.contrib.fixers.ProxyFix Does that help you? Cheers, -Spencer From: Flask [mailto:flask-bounces+spenceryoung=ufl.edu at python.org] On Behalf Of Per L??s Sent: Thursday, December 08, 2016 9:42 AM To: flask at python.org Subject: [Flask] Access to /static (static files) when deployed with cgi Hi! I am new to flask and have deployed a flask web application based on a flask demo-project with cgi: ScriptAlias /flaskutforskning /path/flaskutforskning/flaskutforskning.cgi in production on the linux server, deployed following instructions at http://flask.pocoo.org/docs/0.11/deploying/cgi/. Se also file tree below. I run the development-server in Visual Studio in my PC using from runserver.py, created by the VS Python tools ? Flask web project, which I guess uses WSGI. See screen images below. The application works fine except the links to static-files are different in development in Visual Studio and in production on the linux server. See file hierarchy below. Development-server in Visual Studio in my PC http://localhost:PORT/static/scripts/SPAshowresult.js In production server: http://www.mydomain.com/flaskutforskning/flaskutforskning/static/scripts/SPAshowresult.js Questions: ? Does anybody have a suggestion how to find a better way to work with paths so there is the same static path in dev and production? ? Is there a better IDE than Visual Studio for development and debugging in the code, step by step? Thank you so much in advance. Best regards, Per L??s . --- flaskutforskning -- - --- __init__.py -- - --- static -- - -- - --- content -- - -- - -- - --- bootstrap.css -- - -- - -- - --- bootstrap.min.css -- - -- - -- - --- site.css -- - -- - --- fonts -- - -- - -- - --- glyphicons-halflings-regular.eot -- - -- - -- - --- glyphicons-halflings-regular.svg -- - -- - -- - --- glyphicons-halflings-regular.ttf -- - -- - -- - --- glyphicons-halflings-regular.woff -- - -- - --- scripts -- - -- - --- autocomplete.js -- - -- - --- bootstrap.js -- - -- - --- bootstrap.min.js -- - -- - --- jquery-1.10.2.intellisense.js -- - -- - --- jquery-1.10.2.js -- - -- - --- jquery-1.10.2.min.js -- - -- - --- jquery-1.10.2.min.map -- - -- - --- jquery.validate.js -- - -- - --- jquery.validate.min.js -- - -- - --- jquery.validate.unobtrusive.js -- - -- - --- jquery.validate.unobtrusive.min.js -- - -- - --- jquery.validate-vsdoc.js -- - -- - --- modernizr-2.6.2.js -- - -- - --- _references.js -- - -- - --- respond.js -- - -- - --- respond.min.js -- - -- - --- SPAshowresult.js -- - --- templates -- - -- - --- about.html -- - -- - --- contact.html -- - -- - --- dynfragasr.html -- - -- - --- dynfrageladan - Copy.html -- - -- - --- dynfrageladan.html -- - -- - --- extendslayout.html -- - -- - --- fragasr.html -- - -- - --- frageladan - Copy (2).html -- - -- - --- frageladan - Copy.html -- - -- - --- frageladan.html -- - -- - --- frageladan_origSPA.html -- - -- - --- index.html -- - -- - --- layout.html -- - -- - --- test.html -- - --- utils.py -- - --- views.py -- - --- views - test.py --- flaskutforskning.cgi --- svnupdate.log --- svnupdate.sh 6 directories, 45 files -- Per L??s Developer Institutet f?r spr?k och folkminnen www.sprakochfolkminnen.se +46 18 652 446 per.laas at sprakochfolkminnen.se -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 18942 bytes Desc: image001.jpg URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image002.jpg Type: image/jpeg Size: 27491 bytes Desc: image002.jpg URL: From brn93 at live.it Fri Dec 9 17:33:50 2016 From: brn93 at live.it (Bruno Colella) Date: Fri, 9 Dec 2016 22:33:50 +0000 Subject: [Flask] Webserver under attack In-Reply-To: References: Message-ID: Hi everyone, I have a VPS with Ubuntu 14.04.4 LTS with a public ip and a small Flask application(at the moment Flask is also the WSGI). Flask is in Debug mode, I know this isn't a good security practice but I need it as it's still under development :( I log everything and recently there was a raise of attacks: here is a sample of the logs. Always different ip, and I've never seen this kind of attacks so I don't know if they are successful or not, my questions are: * What kind of attacks are these? * How can i verify if they hacked my vps? * What is the best way to mitigate? Autoban for invalid requests? Thanks in advance, Bruno -------------- next part -------------- An HTML attachment was scrubbed... URL: From brn93 at live.it Sat Dec 10 07:18:58 2016 From: brn93 at live.it (Bruno Colella) Date: Sat, 10 Dec 2016 12:18:58 +0000 Subject: [Flask] Webserver under attack In-Reply-To: References: Message-ID: My VPS is very essential, ssh on 22 (I know it should be changed), flask on 8000 and a webadmin panel on 10000, so nothing interesting. I'm quite used to php vulnerabilities and sqli, but I can't read that shellcode and I was worried it could be some kind of 0day. I can provide more data if needed. @Christophe BAL and @David Baumgold: I have turned off debug mode, unfortunately I can't have dev and prod enviroment separate at the moment Thanks Bruno Il 12/10/16 11:36 AM, reznov110 ha scritto: I don't really know what is going on , what i saw is a shellcodes junks , maybe someone tries to fuzz your webserver , is there any service that runs on the server with an open port for instance apache or ftp with an old version ??? ?????????? ?? ????????? Samsung Galaxy. -------- ???????? ????????? -------- ??: Bruno Colella ????: 10.12.2016 4:33 (GMT+06:00) ????: flask at python.org ????: Re: [Flask] Webserver under attack Hi everyone, I have a VPS with Ubuntu 14.04.4 LTS with a public ip and a small Flask application(at the moment Flask is also the WSGI). Flask is in Debug mode, I know this isn't a good security practice but I need it as it's still under development :( I log everything and recently there was a raise of attacks: here is a sample of the logs. Always different ip, and I've never seen this kind of attacks so I don't know if they are successful or not, my questions are: * What kind of attacks are these? * How can i verify if they hacked my vps? * What is the best way to mitigate? Autoban for invalid requests? Thanks in advance, Bruno -------------- next part -------------- An HTML attachment was scrubbed... URL: From ziirish at ziirish.info Sat Dec 10 07:36:02 2016 From: ziirish at ziirish.info (Ziirish) Date: Sat, 10 Dec 2016 13:36:02 +0100 Subject: [Flask] Webserver under attack In-Reply-To: References: Message-ID: <20161210123601.GG20321@mail.ziirish.info> Running such application with debug ON on a widely open server is kind of crazy. The least you can do is to add a htaccess or something in front of your application (that's relatively easy since your are running your application through WSGI). You should also think about setting up a firewall and open your development port just to a few IP's that are known to be trusted. Search for the "python wsgi htaccess authentication" keywords. Example: http://stackoverflow.com/questions/11762068/apache-mod-wsgi-basic-authentication-for-django-app * On Saturday, December 10, 2016 at 12:18 PM +0000, Bruno Colella wrote: > My VPS is very essential, ssh on 22 (I know it should be changed), flask on 8000 and a webadmin panel on 10000, so nothing interesting. > I'm quite used to php vulnerabilities and sqli, but I can't read that shellcode and I was worried it could be some kind of 0day. > I can provide more data if needed. > > @Christophe BAL and @David Baumgold: I have turned off debug mode, unfortunately I can't have dev and prod enviroment separate at the moment > > Thanks > > Bruno > > > Il 12/10/16 11:36 AM, reznov110 ha scritto: > I don't really know what is going on , what i saw is a shellcodes junks , maybe someone tries to fuzz your webserver , is there any service that runs on the server with an open port for instance apache or ftp with an old version ??? > > > ?????????? ?? ????????? Samsung Galaxy. > > -------- ???????? ????????? -------- > ??: Bruno Colella > ????: 10.12.2016 4:33 (GMT+06:00) > ????: flask at python.org > ????: Re: [Flask] Webserver under attack > > Hi everyone, > > > I have a VPS with Ubuntu 14.04.4 LTS with a public ip and a small Flask application(at the moment Flask is also the WSGI). Flask is in Debug mode, I know this isn't a good security practice but I need it as it's still under development :( > > I log everything and recently there was a raise of attacks: here is a sample of the logs. > > Always different ip, and I've never seen this kind of attacks so I don't know if they are successful or not, my questions are: > > > * What kind of attacks are these? > * How can i verify if they hacked my vps? > * What is the best way to mitigate? Autoban for invalid requests? > > Thanks in advance, > > > Bruno > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask From pierre.chaisy at milibris.com Thu Dec 15 04:27:57 2016 From: pierre.chaisy at milibris.com (Pierre CHAISY) Date: Thu, 15 Dec 2016 10:27:57 +0100 Subject: [Flask] New flask extension Message-ID: <98f982ba-88bf-3eb6-3e2b-071a56eb40f6@milibris.com> Hello, i have created a flask extension: https://github.com/miLibris/flask-rest-jsonapi and i would like to know how to register it in the flask entension list. This extention follows the jsonapi.org protocol and combines the flexibility of Flask-RESTful and the quick usage of Flask-Restless with a data layer concept that allow you to use any ORM or storage provider. I have made this library because in real life project you want a framework to quickly create simple resource api and also a hudge flexibility to customize the resource. Moreover you ofter need to retrieve data from different data providers so the data layer system provides a way to interface them with a CRUD concept. Thank you for your help. -- Pierre CHAISY From david at davidbaumgold.com Thu Dec 15 08:18:30 2016 From: david at davidbaumgold.com (David Baumgold) Date: Thu, 15 Dec 2016 08:18:30 -0500 Subject: [Flask] New flask extension In-Reply-To: <98f982ba-88bf-3eb6-3e2b-071a56eb40f6@milibris.com> References: <98f982ba-88bf-3eb6-3e2b-071a56eb40f6@milibris.com> Message-ID: To register it, make a pull request to the Flask website repository!?https://github.com/pallets/flask-website/blob/master/flask_website/listings/extensions.py David Baumgold On December 15, 2016 at 4:35:13 AM, Pierre CHAISY (pierre.chaisy at milibris.com) wrote: Hello, i have created a flask extension: https://github.com/miLibris/flask-rest-jsonapi and i would like to know how to register it in the flask entension list. This extention follows the jsonapi.org protocol and combines the flexibility of Flask-RESTful and the quick usage of Flask-Restless with a data layer concept that allow you to use any ORM or storage provider. I have made this library because in real life project you want a framework to quickly create simple resource api and also a hudge flexibility to customize the resource. Moreover you ofter need to retrieve data from different data providers so the data layer system provides a way to interface them with a CRUD concept. Thank you for your help. -- Pierre CHAISY _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From jb at pysecure.io Fri Dec 16 03:28:42 2016 From: jb at pysecure.io (jb at pysecure.io) Date: Fri, 16 Dec 2016 08:28:42 +0000 Subject: [Flask] Flask restless authentication Message-ID: <7cc423fb382691a911f3b96daa8ca182@pysecure.io> Hi, I'm evaluating different REST API plugins for Flask, since I need only very simple access to models created with SQLAlchemy I am thinking about flask restless, however it seems it does not provide authentication out-of-the-box which is also my requirement. Flask restful seems to be an overhead for the task but it seems to mee from my short research that authentication support is better. It seems there is a project at https://github.com/graup/flask-restless-security solving my problem with flask restless but I dislike idea of having another dependency in the project. It also may not be under active development which doesn't help either. So I have 2 questions: 1. can anyone point me into some good practices or example code for providing authentication in case of flask restless? 2. can anyone share their experience with flask restless or flask restful (or any other option I am not considering due to lack of my knowledge) and implementation of authentication functionality for the API? Have a great weekend everybody JB From flask.python.comverse at 9ox.net Fri Dec 16 13:49:04 2016 From: flask.python.comverse at 9ox.net (flask.python.comverse at 9ox.net) Date: Fri, 16 Dec 2016 20:49:04 +0200 Subject: [Flask] Flask Digest, Vol 18, Issue 9 Message-ID: Hi JB, Before starting implementation of authentication, you may want to read the following: 1. https://blog.miguelgrinberg.com/post/restful-authentication-with-flask 2. https://blog.miguelgrinberg.com/post/oauth-authentication-with-flask 3. https://stackoverflow.com/questions/6972999/flask-user-authentication 4. https://blog.openshift.com/use-flask-login-to-add-user-authentication-to-your-python-application/ And of course, it never hurts to read https://pythonspot.com/en/login-authentication-with-flask/ ;-) Bye, Ron. --- [image: Tree image] Please remember the environment before printing. Message: 1 > Date: Fri, 16 Dec 2016 08:28:42 +0000 > From: jb at pysecure.io > To: flask at python.org > Subject: [Flask] Flask restless authentication > Message-ID: <7cc423fb382691a911f3b96daa8ca182 at pysecure.io> > Content-Type: text/plain; charset=US-ASCII; format=flowed > > Hi, > I'm evaluating different REST API plugins for Flask, since I need only > very simple access to models created with SQLAlchemy I am thinking about > flask restless, however it seems it does not provide authentication > out-of-the-box which is also my requirement. Flask restful seems to be > an overhead for the task but it seems to mee from my short research that > authentication support is better. It seems there is a project at > https://github.com/graup/flask-restless-security solving my problem with > flask restless but I dislike idea of having another dependency in the > project. It also may not be under active development which doesn't help > either. > > So I have 2 questions: > > 1. can anyone point me into some good practices or example code for > providing authentication in case of flask restless? > 2. can anyone share their experience with flask restless or flask > restful (or any other option I am not considering due to lack of my > knowledge) and implementation of authentication functionality for the > API? > > Have a great weekend everybody > JB > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 18, Issue 9 > ************************************ > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.dorfner at stud.hs-regensburg.de Wed Dec 28 05:32:16 2016 From: andreas.dorfner at stud.hs-regensburg.de (Andreas Dorfner) Date: Wed, 28 Dec 2016 11:32:16 +0100 Subject: [Flask] Error when transferring data to a template Message-ID: Hello everyone, I've created a data-logger using Flask-SQLAlchemy. In the second part of the project, a webserver is set up to commit some of the database data to a website. Because there is an infinite loop at the logger file, another python file called webserver.py (code attached) is used to do so. The operation is planed as follows: 1. If the website is called, the login-window should appear. ---> This part is working so far! 2. After a successful login, the home() function in the webserver.py file should redirect to the show_entries() function. 3. The show_entries() function read some data from the database; in this case the data with id=5 (this part is working as well); and passes the entries to the show_entries.html template. 4. Depending on whether you are logged in or not, different data is shown on the website. The login is working well, but if I press the Login button, I get an error from the webbrowser. Does something going wrong by passing data to the template or is the template the problem (maybe the if-else-statement to be sure that the user is logged in)? Thanks for your help! Kind regards, Andreas --- Diese E-Mail wurde von Avast Antivirus-Software auf Viren gepr?ft. https://www.avast.com/antivirus -------------- next part -------------- #all the imports import time from flask import Flask, flash, redirect, render_template, request, session, abort from flask_sqlalchemy import SQLAlchemy import os #-------------------------------------------------------------------------- #import the database models from models.py from models import Phase1, Phase2, Phase3, PhaseTotal #-------------------------------------------------------------------------- # configuration USERNAME = 'xxxxxx' PASSWORD = 'yyyyyyyy' #--------------------------------------------------------------------------- # create my little application :) app = Flask(__name__) app.config.from_object(__name__) #--------------------------------------------------------------------------- # read data with id 5 from the database and display it to the screen #L1 = Phase1.query.filter_by(id=5).first() #print "BP1" #print(L1.Urms, L1.Qrms) #--------------------------------------------------------------------------- # home function @app.route('/') def home(): if not session.get('logged_in'): return render_template('login.html') else: # return render_template('show_entries.html') return redirect(url_for('show_entries')) #--------------------------------------------------------------------------- #This function pass the entries as dicts to the show_entries.html template #and return the broadcasted one. @app.route('/show') def show_entries(): L1 = Phase1.query.filter_by(id=5).first() entries = [dict(title='Phase 1 with ID 5', Urms=L1.Urms, Irms=L1.Irms, Prms=L1.Prms)] flash('Data for Phase 1 is available!') return render_template('show_entries.html', entries=entries) #--------------------------------------------------------------------------- #Login function @app.route('/login', methods=['GET', 'POST']) def login(): error = None if request.method == 'POST': if request.form['username'] != app.config['USERNAME']: error = 'Invalid username' elif request.form['password'] != app.config['PASSWORD']: error = 'Invalid password' else: session['logged_in'] = True flash('You were logged in') return home() return render_template('login.html', error=error) #--------------------------------------------------------------------------- #Logout function @app.route('/logout') def logout(): session.pop('logged_in', None) flash('You were logged out') return home() #--------------------------------------------------------------------------- #Run the file as a standalone application on IP address 192.168.7.2 (BBB) #at Port 5000 if __name__ == '__main__': app.secret_key = os.urandom(12) app.run(host = '192.168.7.2', port=5000) #--------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidnieder at gmx.de Thu Dec 29 11:40:34 2016 From: davidnieder at gmx.de (David Nieder) Date: Thu, 29 Dec 2016 17:40:34 +0100 Subject: [Flask] Error when transferring data to a template In-Reply-To: References: Message-ID: <4b3baf30-55f3-44a0-a00a-d06c0c5f6f75@gmx.de> On 28.12.2016 11:32, Andreas Dorfner wrote: > Hello everyone, > > I've created a data-logger using Flask-SQLAlchemy. > > In the second part of the project, a webserver is set up to commit some > of the database data to a website. > Because there is an infinite loop at the logger file, another python > file called webserver.py (code attached) is used to do so. > > The operation is planed as follows: > 1. If the website is called, the login-window should appear. > ---> This part is working so far! > 2. After a successful login, the home() function in the webserver.py > file should redirect to the show_entries() function. > 3. The show_entries() function read some data from the database; in this > case the data with id=5 (this part is working as well); > and passes the entries to the show_entries.html template. > 4. Depending on whether you are logged in or not, different data is > shown on the website. > > The login is working well, but if I press the Login button, I get an > error from the webbrowser. Does something going wrong by > passing data to the template or is the template the problem (maybe the > if-else-statement to be sure that the user is logged in)? > Hey Andreas. One mistake in your code I could spot: There is no 'entry' variable in you template just the list 'entries'. So you probably forgot to iterate over the list: {% if session.logged_in %} {% for entry in entries %}

{{ entry.title }}

{% endfor %} {% else %} not logged in {% endif %} Cheers David > Thanks for your help! > Kind regards, > Andreas > >