I have created the following Flask application in python (named simpleflask.py
), using the code below:
from flask import Flask
import random
app = Flask(__name__)
app.secret_key = 'This is really unique and secret'
@app.route('/')
def index():
a = random.randrange(2)
if a == 1:
return "<p>the random number selector returned 1</p>"
else:
return "<p>the random number selector returned 0</p>"
if __name__ == "__main__":
app.run()
The Flask app runs fine from my personal computer.
I then tried to create a .cgi application using the instructions provided in the Flask documentation, which features the following code:
from wsgiref.handlers import CGIHandler
from simpleflask import app
CGIHandler().run(app)
However, it does not work as expected. I keep receiving the following error message:
KeyError: 'SERVER_NAME'
Status: 500 Internal Server Error
Content-Type: text/plain
Content-Length: 59
A server error occurred. Please contact the administrator.
I am not quite sure what this is supposed to mean. Any idea why I am receiving this error? What changes would I have to make to be able to create my .cgi application? Any and all suggestions welcome.