简体   繁体   中英

Trying to pass list value from python to html

I'm trying to pass list values (from 'ci' list below) into my wepage using python. The list values contain URLs for images which will go in the HTML <img src {{ listname[1] }} tag (see HTML below for more info). However, when I try the below code and render the template on my local server the img does not appear and when I inspect element the img src tag is empty.

My code is below:

Python

@app.route('/route', methods=['GET', 'POST'])
def _get_gallery():
    df=pd.read_csv('C:\\username\\foldername\\excelfile.csv')
    images=list(df["image"].values)
    clean_images=[]
    for image in images:
        if "https" in str(image):
            clean_images.append(image)

    ci=pd.DataFrame(clean_images)
    return render_template('template.html', ci=ci)

if __name__ == '__main__':
    app.run(debug=True)

The HTML template has the following code to try and pull through the list values:

 <div class="row">
        <div class="col">
          <a href="{{ ci[1] }}">
            <img class="img" src="{{ ci[1] }}" alt="">
          </a>
        </div>

I think you don't need to convert the list to pandas DataFrame, try to comment this line and see if its work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM