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 is showing the image widget as follows:
I want to rename the labels - Currently, Clear and Change. [Basically my entire page is no lower case, so I wanted to make these label text also in lower case like currently, clear & change].
Is there any way to do this?
In __init__ method set your field label as empty. This will remove label text. Save this answer.
By default, Django stores files locally, using the MEDIA_ROOT and MEDIA_URL settings. The examples below assume that you're using these defaults. However, Django provides ways to write custom file storage systems that allow you to completely customize where and how Django stores files.
You have many options.
You could be artistic with the use of CSS to make the text lowercase.
or you can change the text that is sent to the browser in python/django.
Ultimately the form fields widget is what controls the html output to the view via a function called render(). The render() function for the "ClearableFileInput" widget uses some variables from the widgets class.
You can make your own custom class subclassing the ClearableFileInput class and substitute your own lowercase text strings. ie:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With