Answer the question
In order to leave comments, you need to log in
Why is the log file not being written?
Hello. Added the function of writing to the log, but for some reason the file itself is not created, so logging does not work. Tell me, what's wrong?
from flask import Flask, render_template, request
from vsearch import search4letters
app = Flask(name)
def log_request(req: 'flask_request', res: str) -> None:
with open('vsearch.log', 'a') as log:
print(req, res, file=log)
@app.route('/search4', methods=['POST', 'GET'])
def do_search() -> 'html':
phrase = request.form['phrase']
letters = request.form['letters']
title = 'Here are your results!:'
results = str(search4letters(phrase, letters))
log_request(request, results)
return render_template('results.html',
the_phrase=phrase,
the_letters=letters,
the_title=title,
the_results=results)
@app.route('/')
@app.route('/entry')
def entry_page() -> 'html':
return render_template('entry.html',
the_title='Welcome to search4letters on the Web!')
if name=='main':
app.run(debug=True)
Answer the question
In order to leave comments, you need to log in
everything is correct, with "a" should be created. You just probably didn't find it. It is created in the current directory. do normal print(os.getcwd())
next to the entry, and you will see the path where your file is located.
But it's a bad idea to write logs like that. There is a logging module for this. Here everything is very detailed and with examples.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question