from django.shortcuts import render def home(request): context = {'name': 'Alice'} return render(request, 'home.html', context)
The render function takes the request, template name, and context dictionary. It returns an HTML page where placeholders like {{ name }} are replaced by values from the context.
from django.shortcuts import render def about(request): context = {'page': 'About'} return render('about.html', context)
The render function requires the request object as its first argument, followed by the template name and context.
Template 'greet.html': <html><body><h1>Hello, {{ user }}!</h1></body></html> View: from django.shortcuts import render def greet(request): return render(request, 'greet.html', {'user': 'Bob'})
The template variable {{ user }} is replaced by the string 'Bob' from the context dictionary passed to render.
from django.shortcuts import render def contact(request): return render(request, 'contact_us.html')
The error means Django cannot find the template file named 'contact_us.html' in any of the configured template directories.
render(request, 'index.html') without providing a context dictionary?The render function's context parameter is optional and defaults to an empty dictionary if omitted. The template renders with no variables replaced.
