前提・実現したいこと
web applicationを作成し、
ログを閲覧したいと思っています。
そこでFlaskを用い、PythonとHTMLのテンプレートを使って
ログ閲覧機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
File "Hello.py", line 36
return render_template('viewlog.html',
^
IndentationError: unexpected indent
該当のソースコード
Python
1from flask import Flask, render_template, request, escape 2from vsearch import search4letters 3 4app = Flask(__name__) 5 6def log_request(req: 'flask_request', res: str) -> None: 7 with open('vsearch.log', 'a')as log: 8 print(req.form, req.remote_addr, req.user_agent, res, file=log, sep='|') 9 10@app.route('/search4', methods=['POST']) 11def do_search() -> 'html': 12 phrase = request.form['phrase'] 13 letters = request.form['letters'] 14 title = 'Results' 15 results = str(search4letters(phrase, letters)) 16 log_request(request, results) 17 return render_template('results.html', 18 the_title=title, 19 the_phrase=phrase, 20 the_letters=letters, 21 the_results=results,) 22@app.route('/') 23@app.route('/entry') 24def entry_page() -> 'html': 25 return render_template('entry.html', 26 the_title='Welcome to search4letters of the website version!') 27 28@app.route('/viewlog') 29def view_the_log() -> 'html': 30 contents = [] 31 with open('vsearch.log') as log: 32 for line in log: 33 contents.append([]) 34 for item in line.split('|'): 35 contents[-1].append(escape(item)) 36 titles = ('form data', 'remote address', 'user agent', 'results') 37 return render_template('viewlog.html', 38 the_title='view the logs', 39 the_row_titles=titles, 40 the_data=contents,) 41if __name__ == '__main__': 42 app.run(debug=True) 43 44
試したこと
インデントが原因だと思い、
当該部分を書き直し、
不要な改行がないように
気を付けましたが、
直りません。
プログラミング初心者で
初歩的な質問かもしれませんが、
よろしくお願いいたします。
回答3件
あなたの回答
tips
プレビュー