I am displaying a form that involves uploading an image in my Django template.
This is the template:
{% extends 'header.html' %}
{% block content %}
<br>
<div class="w-50 card mx-auto">
<div class="card-body text-center">
<h2 class="card-title">New Post</h2>
<form method="post">
{% csrf_token %}
<p><strong>
Title<br>
{{ form.Title }}
</strong></p>
<p><strong>
Description<br>
{{ form.Description }}
</strong></p>
<p><strong>
Image
{{ form.Image }}
</strong></p>
<p><strong>
Election<br>
{{ election_form.PostElection }}
</strong></p>
<button type="submit" class='button btn btn-outline-dark'>Post</button>
</form>
</div>
</div>
{% endblock %}
As you can see, the submit button on the form has some Bootstrap attached. This makes it look different to the Choose File button on the image upload form. How do I apply the Bootstrap applied to the submit button to the button in the form?
To apply Bootstrap 4 styles to your "Choose File" input, you need to modify your Django code to produce the following HTML:
That will produce a file picker that occupies the full width of your card.
If you need to validate the input, you'd need the following HTML:
For more information you can check out this page here:
https://getbootstrap.com/docs/4.0/components/forms/#file-browser
Info on validation is available here:
https://getbootstrap.com/docs/4.0/components/forms/#validation