如何在烧瓶中记录信息?



我正在使用 pythonanywhere.com 来运行我的代码, 我在索引中使用了一个帖子表单.html并且我有一个日志.txt文件,我想记录用户的信息 ip 地址,下面我想要帖子表单。 https://ibb.co/esiJhJ

您可以从request.remote_addr获取IP地址,并使用python默认logging库,您可以轻松地将IP写入文件。

代码示例

import logging
from flask import request
# configure your logging and let the file name is text.log
logging.basicConfig(filename='text.log', 
level=logging.INFO)

@app.route("/your_path", methods=["POST"])
def example():
logging.info("ip: {}".format(request.remote_addr))

您还可以修改写入格式。有关更多详细信息,请访问此处

最新更新