0
我需要使用python燒瓶開發一個web應用程序,並且需要將圖像添加到視圖頁面。但我無法得到它,請幫助我擺脫它。如何使用Python燒瓶將圖像添加到webapp
我需要使用python燒瓶開發一個web應用程序,並且需要將圖像添加到視圖頁面。但我無法得到它,請幫助我擺脫它。如何使用Python燒瓶將圖像添加到webapp
在下面的例子中,圖像存儲在SQLite數據庫中。從那裏,你可以這樣做:
@app.route('/show')
def show_pic():
filename = request.args.get('filename','')
t = (filename,)
cur = g.db.execute('select label from pics where filename=?', t)
label = cur.fetchone()[0]
return render_template('upload.html', filename=filename, label=label)
,然後在模板:
{% macro pic_path(pic) %}
{{ url_for('return_pic', filename='%s' % pic) }}
{% endmacro %}
{% block content %}
{% if filename is defined %}
<div id="image">
<a href="{{ pic_path(filename) }}" target="_blank">
<img class="new" src="{{ pic_path(filename) }}">
</a>
</div>
{% else %}
<ul>
{% for pic in pics %}
<li class="thumb">
<a href="{{ url_for('show_pic', filename=pic.filename) }}">
<img class="thumb" src="{{ pic_path('thumb_'+pic.filename) }}">
</a>
<strong>{{ pic.label }}</strong>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}