I'm testing a simple Django form to upload photos. It's a standard affair:
<form action="{% url 'pic_upload' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<b>Upload photo:</b>
{{ form.image }}<br>
<input class="button"type="submit" value="OK" id="id_submit">
</form>
When I run this, I see a button labelled "Browse" (browser: Firefox), using which I can select a file to upload.
My question is, how do I customize the label on this "Browse" button. For instance, I want it to read "Select Photo" instead of "Browse" (on all browsers).
I see a good answers on SO (e.g. here, here or here) but none of these help me rename the file upload button of a django form.
Here's what I've tried (in vain):
In my forms.py:
class PicUploadForm(forms.ModelForm):
image = forms.ImageField(label="Select Photo")
image.widget.attrs["value"] ='Select Photo'
class Meta:
model = Pic
exclude = ("sender","sending_time",)
fields = ("image",)
def __init__(self, *args, **kwargs):
super(PicUploadForm, self).__init__(*args, **kwargs)
self.fields['image'].widget.attrs.update({'value':'Select Photo'})
In my main.css:
input#id_image{
content:'Select Photo';
width: 100%;
height:100%;
}
The button is still labelled 'Browse' after all of the above changes. What do I do?
Note that I'm looking for a pure CSS solution that works across browsers, including proxy browsers such as Opera Mini.