1

I want to set input tag default value to "http://websamplenow.com/30/userprofile/images/avatar.jpg"

background-image is useless.. I am using django and bootstrap.

My template.

{% extends 'base.html' %}

{% block content %}
<style>
textarea.form-control {
  height: 500%;
}
</style>

<div class="container" style="padding-top: 60px;">
    <h1 class="page-header">Edit Profile</h1>
    <div class="row">
        <form class="form-horizontal" method="post" enctype="multipart/form-data">
            {% csrf_token %}
        <!-- left column -->
            <div class="col-md-2 hidden-xs">
                <img id="image" class="img-responsive img-thumbnail" />
                <input name="image" id="files" type="file" class="text-center well-xs">
            </div>

        <!-- edit form column -->
            <div class="col-md-8 col-sm-6 col-xs-12 personal-info">
                <div class="form-group">
                    <label class="col-md-3 control-label"></label>
                    <div class="col-md-8">
                        <button class="btn btn-primary" type="submit">submit</button>
                        <span></span>
                        <a class="btn btn-default" href="{% url 'soldier-list' %}">&nbsp;&nbsp;cancel&nbsp;&nbsp;</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<script>
 document.getElementById("files").onchange = function () {
    var reader = new FileReader();
    reader.onload = function (e) {
        // get loaded data and render thumbnail.
        document.getElementById("image").src = e.target.result;
    };
    // read the image file as a data URL.
    reader.readAsDataURL(this.files[0]);
};
</script>
{% endblock %}

Please help me. Thanks.

최연석
  • 63
  • 1
  • 7

1 Answers1

0

You can't, for security reasons. If you could, you could create invisible file inputs on the page and assign them default values and possibly upload images unknowingly from the client.

Check out this answer on stackoverflow: How to set a value to a file input in HTML?

Community
  • 1
  • 1
jas7457
  • 1,712
  • 13
  • 21