python / beginner
Snippet
Basic Template Rendering
The render function takes a request, a template path, and a dictionary (context) to generate the final web page sent to the user.
snippet.py
1
2
3
4
5
6
from django.shortcuts import renderdef home_view(request):data = {"site_name": "My Blog", "posts_count": 5}# Combines a template with data to produce HTMLreturn render(request, "home.html", data)
django
Breakdown
1
data = {...}
A dictionary containing the information we want to display in the HTML.
2
render(request, "home.html", data)
The framework function that merges the template file with our data.