[Flask] endpoint when running flask app as cgi?

Stuart McGraw smcg4191 at mtneva.com
Mon Apr 16 00:28:18 EDT 2018


Thanks for that suggestion and sorry for the delay in responding...
I put both files I showed in my original post (app file and the cgi
shim) directly into the cgi-bin directory (and removed the now unneeded
"import" statement in the cgi shim file) but got the same result (a 404
error).

Things worked as advertised when I was a little more careful with
the rewrite rules suggested in the docs.
   (http://flask.pocoo.org/docs/0.12/deploying/cgi/)

My situation is that my Flask application will run on a system
with minimal sys admin availability.  I'd like to avoid any Apache
configuration beyond basic cgi.  What I'm hoping for is to be able
to drop a myapp.py file in the system cgi-bin directory and have
the app available at http://xx.com/cgi-bin/myapp.py/...

Is there something I can do in either the flask app or the cgi shim
that will have the same effect as the Apache rewrite rules suggested
in the docs?

I tried changing the values of the SCRIPT_NAME and REQUEST_URI
environ values in the cgi shim, before it calls app.run() but without
success, unsuprisingly because I don't understand what Werkzeug does
with the environment values it gets and how those relate to the
Flask routing decorator urls.

Is there somewhere that describes how the cgi environment values get
turned into values that get matched against the url rules?  Or where
I can look in the Flask/Werkzeug source?

Thanks...

On 04/10/2018 02:12 PM, keith macdonald wrote:
 > Just wondering, is the root folder for the Flask app-route the same as the
 > cgi-bin folder?
 >
 > From: Stuart McGraw <smcg4191-leYhvgBsSa7QT0dZR+AlfA at public.gmane.org>
 > The following, myapp.py, runs fine when I run it directly (ie using Flask's
 > built-in server):
 >     App = Flask ('myapp')
 >     @App.route('/')
 >     def hello_world():
 >       return 'Hello, world'
 >     def main():
 >       App.run (host='0.0.0.0', debug=True)
 >     if __name__ == '__main__': main()
 >
 > But I want to run it as a cgi script so per the Flask docs I created the
 > following, cgiapp.py in my webserver's cgi-bin/ directory:
 >
 >     #!/usr/bin/python3
 >     import sys; sys.path.append ('/home/me/devel')
 >     from wsgiref.handlers import CGIHandler
 >     from myapp import App
 >     CGIHandler().run (App)
 >
 > But when I access the url for the cgi script I get a 404 error.
 >
 > I am certain the web server, cgi, etc is configured correctly (if I replace
 > the CGIHandler call with print statements, the I get the expected web page;
 > the 404 is being generated by Flask in the app code.)
 >
 > I guess I need something other than "/" in the App.route() decorator but I
 > am not sure what.  I *have* read the Flask docs (multiple times) without
 > enlightenment and my stab-in-the-dark guesses not been productive.
 > Hints?  (or better yet an answer?




More information about the Flask mailing list