0

I am using Django 2.2 for a project, I want to remove the currently displayed image link from the user update form as shown in the image below, how do I do this?

image

forms.py


from .models import Profile



class CreateUserForm(UserCreationForm):
    class Meta:
        model = get_user_model()
        fields = ['username', 'email', 'password1', 'password2']
        
        
class UserUpdateForm(forms.ModelForm):
    email = forms.EmailField()

    class Meta:
        model = User
        fields = ['username', 'email']
        help_texts = {
            'username': None,
        }

class ProfileUpdateForm(forms.ModelForm):
    class Meta:
        model = Profile
        fields = ['profile_pic']
  • 1
    You are using the preconfigured `UserCreationForm`, which makes it much harder to customize. In general, I avoid Django Forms for that exact reason; they are too far built into the system, which makes them harder to customize. – Nat Riddle Dec 24 '20 at 15:46
  • I agree with Nat. You could also create a new widget and specify that new widget for profile_pic as described here: https://stackoverflow.com/questions/4707192/django-how-to-build-a-custom-form-widget – robline Dec 24 '20 at 21:24
  • did you fix this? – Destiny Franks Sep 19 '22 at 13:25

1 Answers1

0

You can try to change ImageField to FileInput using widgets. I use Django version 4.1.1 and it works for me.

# forms.py

class ProfileUpdateForm(forms.ModelForm):
    profile_pic = forms.ImageField(widget=forms.FileInput)

    class Meta:
    ...

enter image description here