Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3312362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:59:10+00:00 2026-05-17T21:59:10+00:00

I have a view that enables users to edit their profiles (usual name, username

  • 0

I have a view that enables users to edit their profiles (usual name, username etc) and a image contained in an ÌmageField within the UserProfile:

@login_required
def editprofile(request):
        user = request.user
        if request.method == 'POST':
                edit_form = EditProfileForm(data = request.POST, user = user)
                if edit_form.is_valid():
                        user = edit_form.save()
                        request.user.message_set.create(message='Votre profil a été modifié.')
                        return HttpResponseRedirect('/')
        else:
                dict = {'first_name':user.first_name, 'last_name':user.last_name, 'email':user.email, 'username':user.username}
                edit_form = EditProfileForm(user = user, data = dict)
        tpl_dict = {'form' : edit_form}
        return render_to_response('editprofile.html', tpl_dict, RequestContext(request))

and the form is:

class EditProfileForm(forms.Form):
    first_name = forms.CharField(max_length = 100, required=False)
    last_name = forms.CharField(max_length = 100, required=False)
    email = forms.EmailField()
    username = forms.CharField(max_length = 100)
    avatar = forms.ImageField(required = False)

    def __init__(self, user, *args, **kwargs):
        super(EditProfileForm, self).__init__(*args, **kwargs)
        self.user = user

    def save(self):
        user = self.user
        user.email = self.cleaned_data['email']
        user.username = self.cleaned_data['username']
        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']
        user.save()
        profile = user.get_profile()
        profile.avatar = self.cleaned_data['avatar']
        profile.save()
        return user

the problem is that i need to pass a `request.FILES’ to the form!
I’ve tried

edit_form = EditProfileForm(data = request.POST, request.FILES, user = user)

and other variants without succes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:59:11+00:00Added an answer on May 17, 2026 at 9:59 pm

    When you are overriding the constructor of a form it is a good idea to pass the arguments named instead of just in order. So, I would do:

    edit_form = EditProfileForm(user=user, data=request.POST, files=request.FILES)
    

    That way it is clear to someone reading the code that you have a non-standard form that expects a user argument and it makes explicit which arguments you are passing.

    Alternatively, if you’d insist on calling the constructor without naming the arguments, the correct way to do so is:

    edit_form = EditProfileForm(user, request.POST, request.FILES)
    

    since user is the first argument to your constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that has a list of jobs in it, with data
I have a view that I want to add some custom drawing to. I
I have a View that can vary significantly, depending on the 'mode' a particular
I have a view that is joining two tables and ordering by the first
I have a view that is loaded in the MainWindow.xib. It is just a
I have a view that takes data from my site and then makes it
I have a view that I want to be converted into JSON. What is
I have a view that contains two NSTextFieldCell s. The size at which these
I have a view that will be displaying downloaded images and text. I'd like
We have a view that, without constraints, will return 90 million rows and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.