开发者

Access Image through (Model)Form Field (was: Image Preview in (Model)Form)

开发者 https://www.devze.com 2022-12-16 22:52 出处:网络
can I access an image via a form-field in the template? <p> {% if field.errors %} <span class=\"error\">{{ field.errors }}</span>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消