Skip to content

Code Artisan Lab

Learn PHP, Python & JavaScript

  • Home
  • Services
    • Web Designing
    • Web Development
    • Mobile App Development
    • API Development
  • Softwares
  • Mobile App
  • Training
  • My account
  • Contact Us
  • Vendors
  • Enquiry Now

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

  • Create Invoices Easily with InvoiceUp Create Invoices Easily with InvoiceUp
  • TradeGo - Add Listing Everywhere TradeGo - Add Listing Everywhere
  • Expense Tracker - Easily Track Expense Anytime Expense Tracker - Easily Track Expense Anytime
  • 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
  • Blog (12)
  • Bootstrap (2)
  • Flutter (2)
  • JavaScript (6)
  • JWT (2)
  • Mobile App (4)
  • Mobile App Development (9)
  • Next.js (7)
  • Nuxt.js (1)
  • Offline Training (3)
  • Python Django (15)
  • React .js (5)
  • React Native (5)
  • Services (13)
  • Tailwind (2)
  • Web Development (13)

Recent Posts

  • Learn Tailwind CSS in Ten Days with Easy Step-by-Step Guide
  • Learn Bootstrap in Ten Days with Easy Step-by-Step Guide Plan
  • Bootstrap and Tailwind CSS Comparison for Modern, Responsive Web Development
  • Django vs Python: Understanding Which Is Easier for Developers Today
  • Why JWT Is Better Than Other Authentication Methods for Security?
Proudly powered by WordPress
%d