hello and I hope this email finds you well given the health crisis! I have a very strange problem. I have a function, extractImages(folder) which returns a list of image:
def extractImages(folder):
# variable to store links to the images in the folder
images = []
if os.path.exists(folder):
entries = os.scandir(folder)
for entry in entries:
#print(entry)
if entry.is_file():
filename = entry.name
if allowed_file(filename):
filepath = os.path.join("/" + folder, filename)
images.append(os.path.normpath(filepath))
return images
The have the home endpoint that calls this function:
@app.route('/', methods=['GET'])
@app.route('/index', methods=['GET'])
@app.route('/home', methods=['GET'])
def home():
images = {
'carousel': extractImages(CAROUSEL_FOLDER),
'gallery': extractImages(GALLERY_FOLDER)
}
return render_template('home.html', title='Home', images=images)
The template:
{% block content %}
<p>Carousel images: {{ images['carousel'] }}</p>
<p>Gallery images: {{ images['gallery'] }}</p>
<img src="{{ images['gallery'][0] }}" \>
{% endblock content %}
On localhost, this works great: <p>Carousel images: ['\static\images\carousel\slide-1.jpg', '\static\images\carousel\slide-2.jpg', '\static\images\carousel\slide-3.jpg', '\static\images\carousel\slide-4.jpg']</p> <p>Gallery images: ['\static\images\gallery\1.jfif', '\static\images\gallery\10.jfif', '\static\images\gallery\11.jfif', '\static\images\gallery\12.jfif', '\static\images\gallery\13.jfif', '\static\images\gallery\14.jfif', '\static\images\gallery\15.jfif', '\static\images\gallery\16.jfif', '\static\images\gallery\2.jfif', '\static\images\gallery\3.jfif', '\static\images\gallery\4.jfif', '\static\images\gallery\5.jfif', '\static\images\gallery\6.jfif', '\static\images\gallery\7.jfif', '\static\images\gallery\8.jfif', '\static\images\gallery\9.jfif']</p>
<p>But when I deploy it to pythonanywhere, the images dictionary which i passed to the template is empty!!! Please help!</p>