Jul 252009

It performs three functions.
1. load the template
2. render the output
3. create the HttpResponse
e.g., In views.py
————-
from django.shortcuts import render_to_response
def home_page(request):
return render_to_response(’home.html’,
{’card_list’:Card.objects.all(), ‘user’: request.user})
——–
home.html
is the name of the template file
{’card_list’:Card.objects.all(), ‘user’: request.user}
is the Context to pass to the home.html

Posted by weboom at 12:46 pm Tagged with: , ,
Jul 252009

Context
is a class used to represent the variables for a template.
Pass it to a Python dictionary containing the names of the variables and their values.
———-
e.g., the below Context
{’card_list’:Card.objects.all(), ‘user’=request.user}
——————–
this will go to template and used
——————–
{% if user.is_authenticated %}
Welcome {{ user }} <br></br>
<a href=”{% url logout %}”>Logout</a>
{% else %}
<a href=”{% url login %}”>Login</a> |
<a href=”{% url [...]

Posted by weboom at 12:40 pm Tagged with:
Switch to our mobile site
Top Footer