I am writing to give an answer after almost a year, because this answer is incomplete and because the proposal to leave / $ 1 is incorrect. Other stackoverflows that can be achieved by searching the web using the string "checkbox deployment flag on cgi" also ended without satisfactory solutions.
To begin with, my .htaccess file is exactly the same as in the reference document "flask via CGI", except that the comment in the second line for RewriteCond must be deleted, because in .htaccess any comment must occupy a whole line.
I put the .htaccess file in the root folder of the public_html document, and my cgi script is / home / myusername / public _html / scgi-bin / moc / cgiappserver-prod.cgi.
This is Python, of course, and the shebang at the top is better off being right. On my ISP, they use cpanel, which has a wrapper for CGI, which they call "scgi". This, unfortunately, is not the real thing . Therefore, consider it like regular CGI for the purpose of launching Flask.
I must add that I only have an account with shared hosting.
Here is my cgiappserver-prod.cgi file:
#!/home/myusername/local/bin/python import cgitb; cgitb.enable() # This line enables CGI error reporting from wsgiref.handlers import CGIHandler import traceback from settings import LGGR app = None try: import moc app = moc.app except Exception, e: LGGR.info( traceback.format_exc([10]) ) LGGR.info( 'Problem in cgiappserver-prod with moc import: %s' % e ) class ScriptNameStripper(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): environ['SCRIPT_NAME'] = '' return self.app(environ, start_response) app = ScriptNameStripper(app) try: CGIHandler().run(app) except Exception, e: LGGR.info( traceback.format_exc([10]) ) LGGR.info( 'Problem in cgiappserver-prod with CGIHandler().run(): %s' % e )
So, my application is distributed across several files with the settings.py and moc.py parameters, in particular, in the above code.
My watch as we walked around was partly due to all the useless messages on this subject that I read, but mainly due to the fact that I did not receive messages about receiving error messages early enough. (I have access to the error log provided by the provider, but this is rarely useful.)
To get started, I confirmed that the cgitb.enable () function works. I deliberately sealed wsgiref and saw a beautiful error page, and I commented out the cgitb (cgi traceback) line to see how the error message turned into a useless 500 status code.
Please note that I also set in settings.py the registrar, the rotating LGGR file registrar. With this, I found that I needed to do something additional - not shown here --- tell the Python interpreter where the sqlite3 library is located.
Alternatively, you can simply use the print statements that the mentioned flag documents in CGI talk about:
- With CGI, you will also need to make sure that your code does not contain any print instructions or that sys.stdout is overridden by something that does not write to the HTTP response.
This is true, but it is useful when debugging to see the print record in the HTTP response.
Finally, when I eventually got it working, the browser location window, unfortunately, had something like www.mysite.com/scgi-bin/moc/cgiappserver-prod.cgi/contact in it, whereas I really you just need www. mysite.com/contact.
The exception was the ScriptNameStripper class in cgiappserver-prod.cgi. I got it from other flag documents .