Home > Mobile >  File upload button
File upload button

Time:11-09

I would like to have a file upload button for a models.ImageField. However, I don't want it to render with choose file:no file chosen. Instead, I would like a file upload button that pops up a select file button. Is this possible?

CodePudding user response:

Not at all django related but the easiest way to do it is to add a hidden attribute to your input then style it accordingly:

<input type="file" id="upload" hidden/>
<label for="upload">Choose file</label>
label{
  display: inline-block;
  background-color: indigo;
  color: white;
  padding: 0.5rem;
  font-family: sans-serif;
  border-radius: 0.3rem;
  cursor: pointer;
  margin-top: 1rem;
}
  • Related