The Django `request` Object — A Beginner's Guide

What Is the request Object?

When someone visits a page on your Django site, Django automatically creates a request object and passes it to your view. It contains everything about that visit — who the user is, what they sent, and how they sent it.

You've already been using it every time you write this:

def my_view(request):
    return HttpResponse("Hello!")

That request sitting there as the first argument? That's it.


Fields — The Data Inside request

request.method

Tells you how the page was requested — either "GET" (just loading a page) or "POST" (submitting a form).

def my_view(request):
    if request.method == "POST":
        # user submitted the form
    else:
        # user just loaded the page

You'll write this pattern in almost every view that has a form.


request.GET

Holds any extra data passed in the URL after a ?.

/search/?q=django
query = request.GET.get("q")  # "django"

Always use .get() — it returns None instead of crashing if the key isn't there.


request.POST

Holds the data a user submitted through a form.

username = request.POST.get("username")
password = request.POST.get("password")

This is only filled when request.method == "POST". On a normal page load, it's empty.


request.user

The person currently logged in. If no one is logged in, Django gives you an AnonymousUser instead.

user = request.user
print(user.username)  # "parthi"

This is one of the most useful fields. You'll use it constantly for showing the right content to the right person.


request.user.is_authenticated

A simple True or False — is this person logged in or not?

if request.user.is_authenticated:
    # show their dashboard
else:
    # send them to the login page

Use this any time you want to protect content or personalise a page for logged-in users. It works in views and templates.

In your template:

{% if request.user.is_authenticated %}
    <p>Welcome, {{ request.user.username }}!</p>
{% else %}
    <a href="/login/">Log in</a>
{% endif %}

request.FILES

Contains any files a user uploaded through a form.

uploaded = request.FILES.get("document")

For this to work, your HTML form needs enctype="multipart/form-data":

<form method="post" enctype="multipart/form-data">

request.path

The URL path of the current page, without the domain.

request.path  # "/dashboard/"

Useful in templates to highlight the active nav link:

{% if request.path == "/dashboard/" %}
    <li class="active">Dashboard</li>
{% endif %}

request.session

A place to store small bits of data that stick around between page visits for a user.

# Save something
request.session["last_page"] = "/dashboard/"

# Read it back later
last = request.session.get("last_page")

Think of it like a sticky note Django keeps for each user.


A Real Example

Here's how these fields work together in a role-based view — similar to what you're building in your document review project:

from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required

@login_required
def dashboard(request):
    user = request.user

    if not user.is_authenticated:
        return redirect("login")

    if user.role == "reviewer":
        return redirect("reviewer_dashboard")
    elif user.role == "submitter":
        return redirect("submitter_dashboard")

    return render(request, "dashboard.html", {"user": user})
  • request.user — who is logged in
  • request.user.is_authenticated — are they actually logged in?
  • render(request, ...) — makes request available inside the template too

Quick Reference

Field What it gives you
request.method "GET" or "POST"
request.GET Data passed in the URL (?key=value)
request.POST Form data submitted by the user
request.user The logged-in user object
request.user.is_authenticated True if logged in, False if not
request.FILES Uploaded files
request.path Current URL path
request.session Persistent data for this user

Once you get comfortable with these, the request object stops feeling like magic and starts feeling like a toolbox — one you'll reach into on every view you write.