I'm deploying a flask app on AWS ElasticBeanstalk. I created a new venv from terminal and used eb init
to create the instance of the application in AWS. I then used eb create APPNAME-env
to make an environment for the application. On AWS, the health of the site is listed as "OK". However, when I go to the URL, it is a blank white page with no HTML. I looked at the logs, and in web.stdout.log
, there were several errors. All of them were the same Traceback, from importlib.import_module()
. Each error said ModuleNotFoundError: No module named 'application'
. I renamed my main file to application.py
so there would be a module named application
, and created a new app instance and new environment. The error persists and the page remains blank. Why does it want a module named application
, and why isn't it running correctly?
Here's some additional info:
All the Tracebacks were from load_wsgi()
, by the way.
code of application.py:
from flask import render_template, request, url_for, flash, redirect
from flask import Flask
import datetime
import json
from werkzeug.exceptions import BadRequestKeyError
app=Flask(__name__)
Red_Score=0
Green_Score=0
tossupNum=1
@app.route('/',methods=['GET','POST'])
def Tossup():
global Red_Score
global Green_Score
global tossupNum
if request.method=='POST':
if (int(request.form["Tossup_Green"])<=0 and int(request.form["Tossup_Red"])<=0) and tossupNum==20:
return redirect(url_for('final'))
Red_Score+=int(request.form["Tossup_Red"])
Green_Score+=int(request.form["Tossup_Green"])
tossupNum+=1
if int(request.form["Tossup_Red"]) > int(request.form["Tossup_Green"]) and int(request.form["Tossup_Red"])>0:
return redirect(url_for('redBonus'))
if int(request.form["Tossup_Red"]) < int(request.form["Tossup_Green"]) and int(request.form["Tossup_Green"])>0:
return redirect(url_for('greenBonus'))
else:
#TODO: It's resetting the numbers when it redirects from bonus, try to insert data into request saying that this isn't an initial load
#TODO: Try setting the json attribute of request to store the data
if tossupNum==1:
Red_Score=0
Green_Score=0
tossupNum=1
return render_template('Scoresheet_Tossup.html',Red_Score=Red_Score,Green_Score=Green_Score, tossupNum=tossupNum)
def score_from_bonus_data(form):
result=0
try:
if form["Bonus_1"]=='on':
result+=10
except BadRequestKeyError:
pass
try:
if form["Bonus_2"]=='on':
result+=10
except BadRequestKeyError:
pass
try:
if form["Bonus_2"]=='on':
result+=10
except BadRequestKeyError:
pass
return result
@app.route('/redBonus',methods=['GET','POST'])
def redBonus():
global Red_Score
global Green_Score
global tossupNum
#TODO: Make separate redBonus and greenBonus pages so that way you can redirect to specific ones form the tossup page and you only have to deal with one team at a time
if request.method=='POST':
Red_Score+=score_from_bonus_data(request.form)
return redirect(url_for('Tossup'))
else:
return render_template('redBonus.html',Red_Score=Red_Score,Green_Score=Green_Score)
@app.route('/greenBonus',methods=['GET','POST'])
def greenBonus():
global Red_Score
global Green_Score
global tossupNum
#TODO: Make separate redBonus and greenBonus pages so that way you can redirect to specific ones form the tossup page and you only have to deal with one team at a time
if request.method=='POST':
Green_Score+=score_from_bonus_data(request.form)
return redirect(url_for('Tossup'))
else:
return render_template('greenBonus.html',Red_Score=Red_Score,Green_Score=Green_Score)
def json_serialize_game(Red_Score, Green_Score):
now=datetime.datetime.now().strftime('%c')
return {
"time":now,
"Red_Score":Red_Score,
"Green_Score":Green_Score
}
@app.route('/final',methods=['GET','POST'])
def final():
global Red_Score
global Green_Score
global tossupNum
if request.method=='POST':
with open('GameLog.json', 'r') as json_reader:
gameLog=json.load(json_reader)
with open('GameLog.json','w') as json_reader:
gameLog[datetime.datetime.now().strftime('%c')]={"Red_Score":Red_Score,"Green_Score":Green_Score}
json.dump(gameLog,json_reader,indent=0)
tossupNum=1
return redirect(url_for('Tossup'))
if Red_Score>Green_Score:
co_lor="red"
elif Red_Score<Green_Score:
co_lor="green"
else:
co_lor="gray"
return render_template('final.html', Red_Score=Red_Score, Green_Score=Green_Score, co_lor=co_lor)
app.run()
Contents of config.yml
:
branch-defaults:
default:
environment: QBScorer5-env
group_suffix: null
environment-defaults:
QBScoringWebsite-dev:
branch: null
repository: null
Qbscoringwebsite-env:
branch: null
repository: null
global:
application_name: QBScorer5
branch: null
default_ec2_keyname: null
default_platform: Python 3.8
default_region: us-east-2
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: null
workspace_type: Application
Thanks! Let me know if you need more info.