<p>我已经找到了我的问题的答案,我只是添加了一些javascript来解决我的问题</p>
<pre><code> <style>
#custom-button {
background: rgba(222, 184, 135, 0);
border-radius: 10px;
cursor: pointer;
border: 0px;
}
#custom-button:hover {
background: rgba(13, 177, 40, 0.226);
border-radius: 10px;
cursor: pointer;
border: 0px;
}
#custom-text {
display: None;
}
</style>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<input type="text" name="text" class="form-control" placeholder="Add a comment..." required="" id="id_text">
<input type="file" hidden="hidden" name="posti" accept="image/*" id="id_posti">
<button type="button" id="custom-button"><i class="far fa-image"></i></button>
<span id="custom-text">no file choosen, yet</span>
<button type="submit" class="btn btn-primary mb-2">submit</button>
</form>
<script type="text/javascript">
const realFileBtn = document.getElementById("id_posti");
const customBtn = document.getElementById("custom-button");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
</script>
</code></pre>