Skip to content
Learn Netverks

Lesson

Step 15/36 42% through track

views-basics

Views basics

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Views basics: the syntax, APIs, and habits you need before advancing in Django.

Teams ship Views basics on every Django codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Views basics in contexts like: SaaS dashboards, CMS-style products, internal tools, and APIs paired with React or mobile clients.

Write Python 3 in the editor and click Run on server—the dev runner executes your script; Django framework lessons also use local startproject for full MVT (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

A view is a callable that takes an HttpRequest and returns an HttpResponse. Views query models, enforce permissions, and choose templates or JSON.

Function-based view

from django.shortcuts import render

def index(request):
    articles = Article.objects.filter(published=True)[:10]
    return render(request, "blog/index.html", {"articles": articles})

HttpResponse shortcuts

  • render() — template + context
  • redirect() — 302 to another URL
  • get_object_or_404() — fetch or 404
  • JsonResponse — JSON APIs

Important interview questions and answers

  1. Q: What must every view return?
    A: An HttpResponse subclass—render and JsonResponse wrap this for you.
  2. Q: request.method values?
    A: GET, POST, PUT, PATCH, DELETE, etc.—branch logic on method for forms.
  3. Q: Fat views anti-pattern?
    A: Views with too much business logic—extract to models/services for testability.

Self-check

  1. What arguments does render() take?
  2. When use get_object_or_404 instead of .get()?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • FBV vs CBV pick?
  • HttpResponse types?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump