OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why is HTML not reading my python variable properly?

  • Thread starter Thread starter bofa
  • Start date Start date
B

bofa

Guest
I currently declare a img_path variable as such:

Code:
return render_template('index.html', img_path = r"redacted.jpg")

It works fine and dandy here:

Code:
<div class="content">
        <div class="image-container">
          <p>{{ img_path }}</p>

and prints "redacted.JPG" to my html page as expected. When I try to display the actual image here though:

Code:
`<img src="/static/{{ img_path }}" alt="Image">`

it no longer works

I have tried several different ways of passing the img_path variable. If I just use the image path it works fine but when i try to pass the path as a variable like above it no longer works... I think the path is being read as /static/\img_path when I pass it and that may be what is causing the issue.
<p>I currently declare a img_path variable as such:</p>
<pre><code>return render_template('index.html', img_path = r"redacted.jpg")
</code></pre>
<p>It works fine and dandy here:</p>
<pre><code><div class="content">
<div class="image-container">
<p>{{ img_path }}</p>
</code></pre>
<p>and prints "redacted.JPG" to my html page as expected. When I try to display the actual image here though:</p>
<pre><code>`<img src="/static/{{ img_path }}" alt="Image">`
</code></pre>
<p>it no longer works</p>
<p>I have tried several different ways of passing the img_path variable. If I just use the image path it works fine but when i try to pass the path as a variable like above it no longer works... I think the path is being read as /static/\img_path when I pass it and that may be what is causing the issue.</p>
Continue reading...
 

Online statistics

Members online
0
Guests online
5
Total visitors
5
Top