[Flask] Access to /static (static files) when deployed with cgi
Young,Spencer P
spenceryoung at UFL.EDU
Fri Dec 9 11:15:04 EST 2016
There's also a CGI middleware fixer that helps handle issues introduced by CGI paths. http://werkzeug.pocoo.org/docs/0.11/contrib/fixers/<http://werkzeug.pocoo.org/docs/0.11/contrib/fixers/#werkzeug.contrib.fixers.ProxyFix>
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 <per.laas at sprakochfolkminnen.se<mailto:per.laas at sprakochfolkminnen.se>> 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<http://www.mydomain.com/flaskutforskning/flaskutforskning> or the sub folder for the view.py file in /flaskutforskning/flaskutforskning<http://www.mydomain.com/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 <per.laas at sprakochfolkminnen.se<mailto:per.laas at sprakochfolkminnen.se>>; flask at python.org<mailto: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<mailto: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
<image001.jpg>
<image002.jpg>
.
--- 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<http://www.sprakochfolkminnen.se/>
+46 18 652 446
per.laas at sprakochfolkminnen.se<mailto:per.laas at sprakochfolkminnen.se>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20161209/7bddb789/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 18942 bytes
Desc: image001.jpg
URL: <http://mail.python.org/pipermail/flask/attachments/20161209/7bddb789/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 27491 bytes
Desc: image002.jpg
URL: <http://mail.python.org/pipermail/flask/attachments/20161209/7bddb789/attachment-0003.jpg>
More information about the Flask
mailing list