1

I am setting up a web app with flask. I try to show remote pictures Flask replaces {{article["image"]}} with https://gitlab.com/MindReadH/Articles/raw/master/spain.png in the following code:

<html>
    <head>
        <title>{{article.title}}</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="{{url_for('static',filename ='vendor/bootstrap/css/bootstrap.min.css')}}">
        <link rel="stylesheet" type="text/css" href="{{url_for('static',filename ='fonts/font-awesome-4.7.0/css/font-awesome.min.css')}}">
        <link rel="stylesheet" type="text/css" href="{{url_for('static',filename ='css/articleDetail.css')}}"/>
    </head>

        <body>
        <div class="container">

            <center><a href="{{url_for('get_article_list',category=category,page=1)}}"><i class="fa fa-arrow-left fa-3x"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="{{url_for('user_index')}}"><i class="fa fa-home fa-3x"></i></a></center>
            <div class="card mb-4">
                <div class="card-body">
                    <h2 class="card-title" align="center">{{ article['title'] }}</h2>
                    <p align="center" class="card-text">{{ article['abstract']}}</p>
                    <p align="center" class="card-text">Category : {{ article['category']}}</p>
                    <p align="center" class="card-text">Article Tags : {{ article['articleTags']}}</p>
                    <p align="center" class="card-text">Authors : {{ article['authors']}}</p>
                    <p align="center" class="card-text">Language : {{ article['language']}}</p>
                    <p align="center" class="card-text">Text : {{ article['text']}}</p>
                    <img src={{article['text']}} class="inline"/>
                    <p align="center" class="inline-text">Image : {{ article['image']}}</p>
                    <img src={{article['image']}} class="inline"/>
                    <p align="center" class="card-text">Video : {{ article['video']}}</p>
                    <video controls><source src={{article['video']}}class="inline"/></video>
                </div>
                <!--<img class="card-img-top" src="http://placehold.it/750x300" alt="Card image cap">-->
            </div>
        </div>
    </body>
</html>

As expected, the first line

<p align="center" class="inline-text">Image : {{ article['image']}}</p

returns Image : https://gitlab.com/MindReadH/Articles/raw/master/spain.png which is the address of the image

But the image is not loaded with the second line. Firefox log says: "loading of all possible resources failed"

Edit

as Luis Melo pointed out, i just missed the quotation marks on the src file:

<img src="{{article['image']}}" class="inline"/>
eddie
  • 415
  • 4
  • 13

1 Answers1

1

The problem is that you are not using quotation in your html.

Try replacing every src and href like these:

<img src={{article['image']}} class="inline"/>

With parameters with quotation:

<img src="{{article['image']}}" class="inline"/>

You can visualize the solution working here along with the same issue you are facing.