Flask-Python:在替换静态文件夹中的文件后,模板无法显示最近的文件,并以相同的名称显示以前的图像

Flask-Python:在替换静态文件夹中的文件后,模板无法显示最近的文件,并以相同的名称显示以前的图像,python,html,flask,Python,Html,Flask,使用 框架——烧瓶 语言——html、python 步骤: 传递要从模板生成的文件的名称 所需的文件名是使用作为映像的后端服务器生成的 在静态文件夹中复制/替换生成的图像 模板在网页上显示图像 但如果生成了两个同名的图像,模板不会显示最近的图像 以下是代码片段: template - <img src="{{ url_for('static',filename=file) }}" style="float:center" width="300" height="200" alt=

使用

  • 框架——烧瓶
  • 语言——html、python
步骤:

  • 传递要从模板生成的文件的名称
  • 所需的文件名是使用作为映像的后端服务器生成的
  • 在静态文件夹中复制/替换生成的图像
  • 模板在网页上显示图像
  • 但如果生成了两个同名的图像,模板不会显示最近的图像 以下是代码片段:

    template -   <img src="{{ url_for('static',filename=file) }}" style="float:center"  width="300" height="200" alt="image not found">
    

    请让我知道,为什么在替换文件后,最近的图像没有显示

    您的浏览器是否正在缓存原始图像?按Ctrl+F5以清除可能的浏览器缓存True,即正在缓存的图像。
    def copyFileAndFindUrl(path):
      IMAGE_DIR='img/gol/'
      STATIC_DIR='./static/'
      url_file = ""
      #get basename of path:-->45:67.jpg
      base_name = getBaseName(path)
      print "baseName:",base_name
      #base_name = 'temp.jpg'
      #concat -> "img/" + baseFileName 
      url_file = IMAGE_DIR + base_name #"img/56:67.jpg" 
      print "url file:",url_file
      #copy(path,concat);return error
      dest_file = STATIC_DIR + url_file
      print "destination file:",dest_file
      if  os.path.exists(dest_file):
           os.remove(dest_file)
           print "removed:",dest_file
           print "checking after re:",os.path.exists(dest_file)
      ret = copyToStatic (path,dest_file)
      if ret :
          url_file = ''
          return ret,url_file
      #return concated file to display in webform
      return ret,url_file