-2
******************** 플라스크를 사용하여 게시판을 만들려고하는데 코드가 완벽하게 작동하기 전에 갑자기 일하는 것을 멈췄다.플라스크 UnboundLocalError : 할당 전에 참조 된 로컬 변수 'shift1'
from flask import Flask, render_template
import datetime
import MySQLdb
app = Flask(__name__)
@app.route('/shutdown', methods=['POST'])
def shutdown():
shutdown_server()
return 'Server shutting down...'
@app.route('/')
def index():
now = datetime.datetime.now()
timestamp = datetime.datetime.now().time()
if datetime.time(7, 30) <= timestamp <= datetime.time(15, 29):
shift1 = "A"
elif datetime.time(15, 30) <= timestamp <= datetime.time(23, 29):
shift1 = "B"
elif datetime.time(23, 30) <= timestamp <= datetime.time(7, 29):
shift1 = "C"
return render_template('hello.html', month=now.month, date=now.day, year=now.year, hour=now.hour, minute=now.minute, second=now.second, shift=shift1)
if __name__ == '__main__':
app.run(host= '0.0.0.0', debug=True)
HTML 코드 :
<html>
<head>
<script>
setInterval(function() {
window.location.reload();
}, 1000);
</script>
<style>
table, td, tr {
text-align: center;
height: 72px;
font-size: 53;
}
</style>
</head>
<body>
<table border="1" width="100%" height="941px">
<tr>
<td colspan="4"><p align="centre"><font color="blue">{{ date }}/{{ month }}/{{ year }}</font></p></td>
<td colspan="4"><p align="centre"><font color="blue">{{ hour }} : {{ minute }} : {{ second }}</font></p></td>
</tr>
<tr>
<td colspan="5"></td>
<td colspan="2" ><font>Shift:</td>
<td colspan="1" ><font color="red">{{ shift }}</td>
</tr>
<tr>
<td colspan="2" width="20%"><font size="28" color="green">Plan</td>
<td width="10%">1</td>
<td></td>
<td rowspan="8" colspan="4"></td>
</tr>
<tr>
<td colspan="2" rowspan="3"></td>
<td width="10%">2</td>
<td></td>
</tr>
<tr>
<td width="10%">3</td>
<td></td>
</tr>
<tr>
<td width="10%">4</td>
<td></td>
</tr>
<tr>
<td colspan="2"height="50px" width="20%"><font size="28" color="green">Actual</td>
<td width="10%">5</td>
<td></td>
</tr>
<td colspan="2" rowspan="3"></td>
<td width="10%">6</td>
<td></td>
</tr>
<tr>
<td width="10%">7</td>
<td></td>
</tr>
<tr>
<td width="10%">8</td>
<td></td>
</tr>
</table>
</body>
</html>
플라스크에 많은 경험이없는 도와 준거하시기 바랍니다, 나는 또한 변수 글로벌
파이썬 (플라스크) 코드를 선언하려고했습니다
오류 :
click here to see the screenshot
,536,913,632 10
질문에있는 모든 오류를 코드 블록 –