Skip to content

Code Artisan Lab

Learn PHP, Python & JavaScript

  • Home
  • Softwares
  • Courses
  • Training
  • My account
  • Contact Us
  • Vendors

Django Tutorial Part 4: User Profiles and Permissions (2025 Beginner Guide)

In Part 3, we added login, logout, and user registration. Now in Part 4, you’ll learn how to create a custom user profile and assign permissions or roles using Django’s powerful auth system.

What You’ll Learn

  • Create a profile model linked to the user
  • Assign and check user permissions
  • Display profile info in templates

Step 1: Create the Profile Model

Create a profile model in models.py:

1
2
3
4
5
6
7
8
9
10
from django.db import models
from django.contrib.auth.models import User
 
class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    bio = models.TextField(blank=True)
    profile_pic = models.ImageField(upload_to='profiles/', blank=True)
 
    def __str__(self):
        return f"{self.user.username} Profile"

Then run:

1
2
python manage.py makemigrations
python manage.py migrate

Step 2: Auto-Create Profile After Registration

In signals.py inside your app:

1
2
3
4
5
6
7
8
9
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import Profile
 
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)

Then connect the signals in apps.py:

1
2
def ready(self):
    import myapp.signals

Step 3: Display Profile Information

Create a view in views.py:

1
2
3
4
5
from django.contrib.auth.decorators import login_required
 
@login_required
def profile(request):
    return render(request, 'myapp/profile.html')

Add URL in urls.py:

1
path('profile/', views.profile, name='profile'),

Create templates/myapp/profile.html:

1
2
3
<h2>Welcome {{ user.username }}</h2>
<p>Bio: {{ user.profile.bio }}</p>
<img src="{{ user.profile.profile_pic.url }}" alt="Profile Picture" />

Step 4: Add and Check Permissions

Django supports groups and permissions. In the admin panel:

  1. Create a group (e.g. “Editors”)
  2. Assign specific permissions (e.g. can add/change Post)
  3. Add users to the group

Check permissions in a view:

1
2
3
4
if request.user.has_perm('myapp.change_post'):
    # allow edit
else:
    return HttpResponse("You don't have permission.")

Optional: Restrict Templates Based on Group

1
2
3
{% if user.groups.all.0.name == 'Editors' %}
    <a href="{% url 'create_post' %}">New Post</a>
{% endif %}

Conclusion

Now you’ve extended Django’s default User model by adding a profile and used the built-in permission system to control access. This sets you up to build dashboards, admin tools, or user roles for different types of users.

Next up in Part 5: Build a blog-style dashboard and let users manage their own content.

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Like this:

Like Loading...
This entry was posted in Blog, Python Django and tagged django access control, django auth groups, django beginner permissions, django custom fields user, django custom profile, django custom user, django django.contrib.auth, django extend user model, django permission system, django permissions, django profile form, django profile model, django profile page, django tutorial part 4, django user attributes, django user authentication, django user groups, django user profile, django user roles, django user type on June 14, 2025 by surajkumar.

Post navigation

← Django Tutorial Part 3: User Login, Logout & Registration (2025 Beginner Guide) Django Tutorial Part 5: User Dashboard and Content Management (2025 Beginner Guide) →

Products

  • Smart GST Accounts Software Smart GST Accounts Software
  • Complete GST Billing Software Complete GST Billing Software
  • Fast & Easy Restaurant Billing Software Fast & Easy Restaurant Billing Software
  • Easy Appointment Booking Easy Appointment Booking
  • All-in-One Hotel Booking Management Software All-in-One Hotel Booking Management Software
  • Manage Projects Faster with Laravel & MySQL System Manage Projects Faster with Laravel & MySQL System
  • Modern Learning Management System Modern Learning Management System
  • Smart Billing Software – Fast, Secure & Scalable Solution for Your Business Smart Billing Software – Fast, Secure & Scalable Solution for Your Business
  • Next-Gen Accounting Software for Modern Businesses Next-Gen Accounting Software for Modern Businesses
  • Modern Accounting Software Modern Accounting Software
  • Blog (12)
  • Flutter (2)
  • JavaScript (3)
  • Mobile App Development (4)
  • Next.js (1)
  • Python Django (9)
  • React Native (1)
  • Web Development (1)

Recent Posts

  • Flutter App with Django Backend Using DRF and PostgreSQL | Complete Guide 2025
  • Flutter App Creation from Scratch | Beginner’s Guide 2025
  • DRF vs FastAPI vs Django Ninja vs Flask: Best Python Web Frameworks Compared in 2025
  • Django vs Laravel: Which Backend Framework is Better in 2025?
  • React Native vs Flutter: Which Framework is Better for Mobile App Development in 2025?
Proudly powered by WordPress
%d