python代码为
@lb.route('/<int:id>/mainpage', methods=('GET', 'POST'))
def mainpage(id)
root_dir = os.path.abspath(os.path.dirname(__file__))
img_path=root_dir+'\static'+'\images'#图片文件存储在static文件夹下的images文件夹内
files = os.listdir(img_path)#获取图片文件名字
if id==len(files):
id=0
file= "/static/images/"+files[id]
return render_template('mainpage.html',file=file)
html代码为
{% block content %}
<img src="{{ file }}"/>
<a class="action" href="{{ url_for('label.mainpage', id=id+1) }}">下一张图片</a>
{% if id != 0%}
<a class="action" href="{{ url_for('label.mainpage', id=id-1) }}">上一张图片</a>
{% endif %}
{% endblock %}