How to Rename the Clear and Change Shortcuts in ImageField Django

I am relatively new to django. I am using ImageForm to get the image path from the user.

class EditProfileForm(ModelForm):
    username = CharField(label='User Name', widget=TextInput(attrs={'class': 'form-control'}), required=True)
    image = ImageField(label='Select Profile Image',required = False)

It displays the image widget as follows:

enter image description here

I want to rename shortcuts - Currently Clear and Change. [In principle, my whole page is not a lowercase letter, so I would like to make this label text lowercase as well, for example, now, clearly and change].

Is there any way to do this?

+4
source share
1 answer

You have many options.

You can be artistic using CSS to make text lowercase.

, python/django.

- , html render(). render() ClearableFileInput .

ClearableFileInput . :

from django.forms.widgets import ClearableFileInput

class MyClearableFileInput(ClearableFileInput):
    initial_text = 'currently'
    input_text = 'change'
    clear_checkbox_label = 'clear'

class EditProfileForm(ModelForm):
    image = ImageField(label='Select Profile Image',required = False, widget=MyClearableFileInput)
+2

All Articles