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

  • SEARCH
  • Home
  • 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 6029179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:50:54+00:00 2026-05-23T04:50:54+00:00

I want that each user on my website will have an image in his

  • 0

I want that each user on my website will have an image in his profile. I don’t need any thumbnails or something like that, just a picture for each user. The simpler the better. The problem is I don’t know how to insert this type of field into my user profile. Any suggestions?

  • 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-23T04:50:54+00:00Added an answer on May 23, 2026 at 4:50 am

    You need to make a form that has a clean method that validates the properties you’re looking for:

    #models.py
    from django.contrib.auth.models import User
    
    class UserProfile(models.Model):
        user   = models.OneToOneField(User)
        avatar = models.ImageField()
    
    
    #forms.py
    from django import forms
    from django.core.files.images import get_image_dimensions
    
    from my_app.models import UserProfile
    
    
    class UserProfileForm(forms.ModelForm):
        class Meta:
            model = UserProfile
    
        def clean_avatar(self):
            avatar = self.cleaned_data['avatar']
    
            try:
                w, h = get_image_dimensions(avatar)
    
                #validate dimensions
                max_width = max_height = 100
                if w > max_width or h > max_height:
                    raise forms.ValidationError(
                        u'Please use an image that is '
                         '%s x %s pixels or smaller.' % (max_width, max_height))
    
                #validate content type
                main, sub = avatar.content_type.split('/')
                if not (main == 'image' and sub in ['jpeg', 'pjpeg', 'gif', 'png']):
                    raise forms.ValidationError(u'Please use a JPEG, '
                        'GIF or PNG image.')
    
                #validate file size
                if len(avatar) > (20 * 1024):
                    raise forms.ValidationError(
                        u'Avatar file size may not exceed 20k.')
    
            except AttributeError:
                """
                Handles case when we are updating the user profile
                and do not supply a new avatar
                """
                pass
    
            return avatar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that accepts user-uploaded images. I want to give each uploaded
I have a website written in asp.net MVC2 that shows random images, each image
I an writing a website that will have multiple skins. Each skin has its
I have a string s that I want to split up so each part
First of all i want to say that i have searched each and every
I have several dataframes in which I want to delete each row that matches
I am developing a website using Codeigniter that will have different subdomains for different
I'm building a website in Django. I want each user of the site to
My website has public-facing profiles. Users may have 145x145 profile images that are displayed
For my website, I want to make something that works a bit like the

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.