Django Tutorial Part 6: Upload and Display Images & Files (2025 Beginner Guide)

In Part 5, we built a user dashboard with content management. Now, let’s enable media uploads so users can upload images and files with their posts or profiles. We’ll configure media settings, add upload fields, and display uploaded files in templates.

What You’ll Learn

  • Configure MEDIA_ROOT and MEDIA_URL
  • Create upload fields for images/files
  • Update views and templates to handle file uploads
  • Serve uploaded files in development

Step 1: Configure Media Settings

In settings.py, add:

In urls.py (project-level), add the following at the bottom:

Step 2: Add an Image Field to Your Post Model

In models.py:

Run migrations:

Step 3: Update the Post Form

In forms.py:

Step 4: Update the Create & Edit Views

Make sure your views accept file uploads:

Step 5: Update Your Templates

create_post.html and edit_post.html should use enctype="multipart/form-data":

Step 6: Display the Uploaded Image

In your dashboard template or post list:

Optional: Upload Files to Profile

To allow users to upload profile pictures or documents, add fields to the Profile model (see Part 4):

Step 7: Install Pillow

For image handling, make sure Pillow is installed:

Conclusion

You’ve successfully added image and file upload functionality to your Django project. Now your users can upload profile pictures, images with posts, or other media. This is a key feature for blogs, portfolios, and content-based platforms.

Coming Next in Part 7: Build a contact form with email functionality using Django’s built-in email system!