I'm creating a new app in django environment. I want to upload image of user when he/she sign-up's in my app and i want to use the same image when he/she posts any comment in my app. So how to integrate image-uploading code into my app code?
You should be using UserProfile
as has been answered here Django user profile and have the ImageField in there.
Then create a ModelForm
for the UserProfile and render it wherever you want the user to setup their profile and add a user image. The Model form will render the ImageField as a file upload field and have default handles for it. Make sure you have MEDIA_URL
configured in your settings.py
. You would also need PIL
installed in your path for the image upload to work.
You can access the UserProfile
instance for your user
doing user.get_profile
in your templates and as a callable elsewhere.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.