
392 Chapter 9
view_the_log 갱신하기
‘view_the_log’ 함수 다시 확인하기
view
_
the
_
log
함수를 살펴본지 오랜 시간이 흘렀으니 다시 한번 함수를 자세히 살펴봅시다.
현재
view
_
the
_
log
함수의 기능을 요약하면 이 함수는
vsearch
.
log
텍스트 파일에서
로깅된 데이터를 추출해
contents
라는 리스트의 리스트로 변환합니다. 그리고 이 데이터를
viewlog
.
html
이라는 템플릿으로 전송합니다.
@app.route('/viewlog')
def view_the_log() -> 'html':
contents = []
with open('vsearch.log') as log:
for line in log:
contents.append([])
for item in line.split('|'):
contents[-1].append(escape(item))
titles = ('Form Data', 'Remote_addr', 'User_agent', 'Results')
return render_template('viewlog.html',
the_title='View Log',
the_row_titles=titles,
the_d ...