实际项目中的代码实现:

    icon = req.files["icon"]
    if icon:
        curr_time = datetime.datetime.now()
        sub_path = os.path.join(settings.ICONS_FILE_DIRS, curr_time.strftime("%Y-%m-%d"))
        if not os.path.exists(sub_path):
            os.mkdir(sub_path)
        file_all_path = os.path.join(sub_path, icon.filename)
        icon.save(file_all_path)
        content_id_str = str(req_dict['id']).zfill(12)
        req_dict['icon'] = curr_time.strftime("%Y-%m-%d_%H%M%S.%f") + '_' + content_id_str + icon.filename
        os.rename(file_all_path, os.path.join(sub_path, req_dict['icon']))

        req_dict['updated_at'] = curr_time.strftime("%Y-%m-%d %H:%M:%S")

    models.db.content_category.update_one({"id": eval(req_dict.pop("id"))}, {"$set": req_dict})

 

相关文章:

  • 2021-06-11
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
  • 2021-05-30
猜你喜欢
  • 2022-12-23
  • 2022-02-27
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
相关资源
相似解决方案