我正在做一个Python Flask项目,试图通过FlaskForm从Postgresql中“编辑”当前的“对象”。到目前为止,我设法使用的值检索“配方”对象的值,但我需要手动呈现{{recipe.description}}。
但是,如何使用输入[file]来检索{{recipe.picture}}呢?
这是我的^5.2.1
form.html
这是我的<form method="POST" action="{{ url_for('recipes.edit_recipe', recipe_id=recipe.id) }}" enctype="multipart/form-data">
{{ form.csrf_token }}
{{ form.hidden_tag() }}
<fieldset class="form-group">
<div class="modal-body">
{% for field in form if field.name != "csrf_token" %}
{% if field.name != "btn" %}
<div class="form-group">
{{ field.label(class="form-control-label form-control-lg") }}
<!-- if fiend.something == title, need to insert title -->
{% if field.name == "picture" %}
{{ field(class="form-control", value=recipe.picture) }}
<figure>
<img src="{{recipe.picture}}" class="small-preview" alt="preview">
<figcaption>Current photo</figcaption>
</figure>
{% endif %}
{% if field.name == "title" %}
{{ field(class="form-control", value=recipe.title) }}
{% endif %}
{% if field.name == "description" %}
<textarea class="form-control" name="description" id="description" cols="30" rows="5">{{ recipe.description }}</textarea>
{% endif %}
<!-- end the if block -->
{% for error in field.errors %}
{{ error }}
{% endfor %}
</div>
{% else %}
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
{{ form.btn(class="btn btn-info") }}
</div>
{% endif %}
{% endfor %}
</div>
</fieldset>
</form>
views.py