title: How do you serve a dynamically downloaded image to a browser using flask?
body: <p>I'm working with an IP camera. I can use a URL such as this one to grab a static image off the camera:</p>
  
  <p><a href="http://Username:Password@IP_of_Camera:Port/streaming/channels/1/picture" rel="nofollow">http://Username:Password@IP_of_Camera:Port/streaming/channels/1/picture</a></p>
  
  <p>What I want to do is have python/flask download the image from that URL when the client loads the page, and embed the image into the page using an img tag.</p>
  
  <p>If I have a template that looks something like this:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Test&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;img src="{{ image }}"&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>how do I replace the {{ image }} with the downloaded image?</p>
  
  <p>Would I use urllib/requests to download the image to flask's static folder, replace {{ image }} with something like <code>{{ url_for('static', filename="temp_image.png") }}</code>, and then delete the image from the static folder when the page loads? Would I download it someplace else instead (other than the static folder)? Or is there some other way to do it that keeps the image in memory?</p>
  
  <p>PS. I know it's possible to replace {{ image }} with that URL directly, but that reveals the username/password/IP/port of the camera to the client.</p>