Render Template in FBV with Context

An FBV example rendering a template with context variables.


# views.py
from django.shortcuts import render

def hello(request):
    context = {"user_name": "Alice", "greeting": "Welcome"}
    return render(request, "hello.html", context)
  

# templates/hello.html
<h1>Hello, {{ user_name }}!</h1>
<p>{{ greeting }}</p>

# urls.py
from django.urls import path
from . import views

urlpatterns = [
    path("hello/", views.hello, name="hello"),
]
  
Explanation:
  • Use render() to combine template rendering with context and HttpResponse.
  • Pass context as a dictionary for clean, testable views.
  • Category Views (FBV & CBV)
  • Total Views 389
  • Last Modified 24 December, 2025
  • Tags #fbv #render #templates #context
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.