The HttpRequest Object
Read method, path, GET, and POST data.
The HttpRequest Object is a free Django Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Meet the Request Object
Django builds an HttpRequest for every visit and passes it to your view as the first argument, usually named request. 📨
def view(request):
return HttpResponse("ok")The HTTP Method
Check request.method to see how the page was asked for. It is a string like GET when reading or POST when submitting data.
if request.method == 'POST':
save_it()The Requested Path
Use request.path to read the URL path the user requested, such as /blog/. It is handy for logging and branching logic.
current = request.path # "/blog/"Query String Data
request.GET holds values from the URL query string. For a link to ?q=django, request.GET reads that q value for you.
term = request.GET.get('q', '')Form Submission Data
request.POST carries data sent in a form submission. Pull a field by its name, just like reading from a dictionary.
name = request.POST.get('name')Safe Defaults with get
Always use .get() on request.GET or POST. It returns a default instead of crashing when a key is missing from the data.
page = request.GET.get('page', 1)Reading Request Headers
The request.headers object lets you read incoming HTTP headers like User-Agent or Accept by their name.
agent = request.headers.get('User-Agent')The Logged-In User
Django attaches request.user so your view knows who is visiting. It is an authenticated user or an anonymous one.
if request.user.is_authenticated:
greet()Cookies on the Request
Read stored cookies through request.COOKIES, a simple dictionary of names and values the browser sent along.
theme = request.COOKIES.get('theme')Session State
The request.session object persists data across requests for one visitor, perfect for a cart or a recent search.
request.session['count'] = 1Files and Uploads
When a form uploads files, find them in request.FILES. Each entry is an uploaded file you can read or save to disk.
upload = request.FILES.get('avatar')Quick Check
Where does Django put data from a submitted form?
Recap: One Object, Everything
The HttpRequest bundles the method, path, GET, POST, headers, user, and more. Read it to understand every visit. 🧰
Frequently asked questions
Is the “The HttpRequest Object” lesson free?
Yes — the full text of “The HttpRequest Object” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.
What will I learn in “The HttpRequest Object”?
Read method, path, GET, and POST data. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Django Academy?
No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The HttpRequest Object” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Django Academy lesson?
Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.