Access Image through (Model)Form Field (was: Image Preview in (Model)Form)
can I access an image via a form-field in the template?
<p>
{% if field.errors %}
<span class="error">{{ field.errors }}</span>
{% endif %}
{{ field.label_tag }}:<br />
<img src="{{ field.value.url }}" /> {# <- This is what I want to do, I know it doesn't work like th开发者_开发技巧is #}
{{ field }}<br />
<span >{{ field.help_text }}</span>
</p>
thanks for your time.
If you wish to display a preview, when user chooses an url in a form, then you must use some javascript. Django forms are static html elements, you must hook some javascript function to the field, which will change image src, when user chooses new image.
精彩评论