前提・実現したいこと
初歩的な質問を失礼します。
HerokuにFlaskのアプリをデプロイし、リンクからアプリを開いたところ、
以下のようなエラーが発生しました。
直し方を教えてほしいです。
ブラウザに表示されているエラーメッセージ
Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
階層
neko
└-Procfile
└-program.py
└-requirements.txt
└-templates
----└-----index.html
----└-----index.css
----└-----correct_answer.png
----└-----incorrect_answer.png
----└-----default.png
ソースコード
Procfile
web: gunicorn program:app --log-file=-
program.py
python
1import psycopg2 2import random 3 4from flask import Flask, render_template 5app = Flask(__name__) 6 7@app.route('/') 8def neko(): 9 random1 = random.randint(1,6) 10 random2 = random.randint(1,6) 11 random3 = random.randint(1,6) 12 random4 = random.randint(1,6) 13 14 while random1 == random2: 15 random2 = random.randint(1,6) 16 while random1 == random3: 17 random3 = random.randint(1,6) 18 while random1 == random4: 19 random4 = random.randint(1,6) 20 while random2 == random3: 21 random3 = random.randint(1,6) 22 while random2 == random4: 23 random4 = random.randint(1,6) 24 while random3 == random4: 25 random4 = random.randint(1,6) 26 27 connection = psycopg2.connect("host=ec2-34-202-54-225.compute-1.amazonaws.com port=5432 dbname=d386ncaa1c2leq user=lhiloksxsqtrbm password=省略") 28 29 cur = connection.cursor() 30 cur.execute('SET search_path TO public;') 31 32 cur.execute("SELECT english FROM neko_record WHERE number = '%s'" % random1) 33 english1 = cur.fetchall() 34 cur.execute("SELECT japanese FROM neko_record WHERE number = '%s'" % random1) 35 japanese1 = cur.fetchall() 36 37 cur.execute("SELECT english FROM neko_record WHERE number = '%s'" % random2) 38 english2 = cur.fetchall() 39 cur.execute("SELECT japanese FROM neko_record WHERE number = '%s'" % random2) 40 japanese2 = cur.fetchall() 41 42 cur.execute("SELECT english FROM neko_record WHERE number = '%s'" % random3) 43 english3 = cur.fetchall() 44 cur.execute("SELECT japanese FROM neko_record WHERE number = '%s'" % random3) 45 japanese3 = cur.fetchall() 46 47 cur.execute("SELECT english FROM neko_record WHERE number = '%s'" % random4) 48 english4 = cur.fetchall() 49 cur.execute("SELECT japanese FROM neko_record WHERE number = '%s'" % random4) 50 japanese4 = cur.fetchall() 51 52 list = [japanese1, japanese2, japanese3, japanese4] 53 random.shuffle(list) 54 choice1=list[0] 55 choice2=list[1] 56 choice3=list[2] 57 choice4=list[3] 58 59 english1_str = str(english1)[3:-4] 60 japanese1_str = str(japanese1)[3:-4] 61 choice1_str = str(choice1)[3:-4] 62 choice2_str = str(choice2)[3:-4] 63 choice3_str = str(choice3)[3:-4] 64 choice4_str = str(choice4)[3:-4] 65 66 return render_template('index.html', title='flask test', 67 english1_str=english1_str, 68 japanese1_str=japanese1_str, 69 list=list, 70 choice1=choice1, 71 choice2=choice2, 72 choice3=choice3, 73 choice4=choice4, 74 choice1_str=choice1_str, 75 choice2_str=choice2_str, 76 choice3_str=choice3_str, 77 choice4_str=choice4_str 78 ) 79 80if __name__ == "__main__": 81 app.run(debug=True) 82
index.html
Html
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4<meta charset="UTF-8"> 5<meta name="viewport" content="width=device-width, initial-scale=1.0, 6maximum-scale=1.0, minimum-scale=1.0"> 7<link rel="stylesheet" href="index.css"> 8<title>test</title> 9<h3>tiile</h3> 10</head> 11 12<body> 13<div class="question"> 14<h3>{{ english1_str }}</h3> 15</div> 16 17<div class="transparent"> 18<label><input type="radio" name="answer" value="transparent">Transparent</label> 19</div> 20<div class="choice"> 21<input id="radio_1" type="radio" name="answer" value="{{ choice1_str }}"> 22<label class="answer" for="radio_1">{{ choice1_str }}</label><br> 23<input id="radio_2" type="radio" name="answer" value="{{ choice2_str }}"> 24<label class="answer" for="radio_2">{{ choice2_str }}</label><br> 25<input id="radio_3" type="radio" name="answer" value="{{ choice3_str }}"> 26<label class="answer" for="radio_3">{{ choice3_str }}</label><br> 27<input id="radio_4" type="radio" name="answer" value="{{ choice4_str }}"> 28<label class="answer" for="radio_4">{{ choice4_str }}</label><br><br> 29</div> 30 31<div class="button_center"> 32<input type="button" class="flat_button" value="答える" id="answer_button" onclick="butotn_click()"> 33</div> 34 35<div id="correct_answer"> 36<p>正解!</p> 37<div class="result"> 38<img src="correct_answer.png"> 39</div> 40<div class="button_center"> 41<input type="button" class="flat_button" value="リロード" onclick="window.location.reload()"> 42</div> 43</div> 44 45<div id="incorrect_answer"> 46<p>もう一度!</p> 47<div class="result"> 48<img src="incorrect_answer.png"> 49</div> 50</div> 51 52<div id="default"> 53<div class="indention"> 54<p>選んでね</p> 55</div> 56<div class="result"> 57<img src="default.png"> 58</div> 59</div> 60 61<script> 62 function butotn_click(){ 63 let click_value = ''; 64 for (let i = 0; i < len; i++){ 65 if (answer_radio.item(i).checked){ 66 click_value = answer_radio.item(i).value; 67 } 68 } 69 if (click_value == 'transparent') { 70 document.getElementById('correct_answer').style.display = "none"; 71 document.getElementById('incorrect_answer').style.display = "none"; 72 document.getElementById('default').style.display = ""; 73 } else if (click_value == '{{ japanese1_str }}') { 74 document.getElementById('correct_answer').style.display = ""; 75 document.getElementById('incorrect_answer').style.display = "none"; 76 document.getElementById('default').style.display = "none"; 77 } else if (click_value != '{{ japanese1_str }}') { 78 document.getElementById('correct_answer').style.display = "none"; 79 document.getElementById('incorrect_answer').style.display = ""; 80 document.getElementById('default').style.display = "none"; 81 } 82 } 83 let answer_radio = document.getElementsByName('answer'); 84 let len = answer_radio.length; 85 answer_radio[0].checked = true; 86 let answer_button = document.getElementById('answer_button'); 87 answer_button.addEventListener('click', butotn_click); 88 window.addEventListener('load', butotn_click()); 89 90var reload =document.getElementById('reload'); 91 reload.addEventListener('click',function(){ 92 window.location.reload(); 93}); 94</script> 95</body> 96</html>
試したこと
ローカルで以下のコマンドを実行したところ、
index.htmlは正しく読めましたが、index.cssやpngファイルは読めませんでした。
Postgresqlからデータを読み込むことはできました。
C:\…\neko>python program.py
補足情報
Flaskとgunicornをpipでインストールしています。
HerokuのPostgresqlを使用しています。
あなたの回答
tips
プレビュー