Django: Views, Templates, and Sessions
CS 370 SE Practicum, Cengiz Günay
(Some slides courtesy of Eugene Agichtein and the Internets)
CS 370, Günay (Emory) Django Views/Templates Spring 2014 1 / 7
Django: Views, Templates, and Sessions CS 370 SE Practicum, Cengiz - - PowerPoint PPT Presentation
Django: Views, Templates, and Sessions CS 370 SE Practicum, Cengiz Gnay (Some slides courtesy of Eugene Agichtein and the Internets) CS 370, Gnay (Emory) Django Views/Templates Spring 2014 1 / 7 Agenda Warm-up project: Anything you are
CS 370 SE Practicum, Cengiz Günay
(Some slides courtesy of Eugene Agichtein and the Internets)
CS 370, Günay (Emory) Django Views/Templates Spring 2014 1 / 7
Warm-up project: Anything you are missing? Progress or problems? Post on Piazza. Still due Feb 13th
CS 370, Günay (Emory) Django Views/Templates Spring 2014 2 / 7
Warm-up project: Anything you are missing? Progress or problems? Post on Piazza. Still due Feb 13th Today: Django Views, Templates, and Sessions
CS 370, Günay (Emory) Django Views/Templates Spring 2014 2 / 7
1/31/2013 CS 370, Spring 2012 2
1/31/2013 CS 370, Spring 2012 3
detail( request=<HttpRequest object> , poll_id='23‘ )
1/31/2013 CS 370, Spring 2012 4
1/31/2013 CS 370, Spring 2012 5
1/31/2013 CS 370, Spring 2012 6
1/31/2013 CS 370, Spring 2012 7
from django.template import Context, loader from polls.models import Poll from django.http import HttpResponse def index(request2): latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5] t = loader.get_template('polls/index.html') c = Context({ 'latest_poll_list': latest_poll_list, }) return HttpResponse( t.render(c) ) loads the template called "polls/index.html" and passes it a context. The context is a dictionary mapping template variable names to Python
1/31/2013 CS 370, Spring 2012 9
1/31/2013 CS 370, Spring 2012 10
1/31/2013 CS 370, Spring 2012 11
1/31/2013 CS 370, Spring 2012 12
1/31/2013 CS 370, Spring 2012 13
1/31/2013 CS 370, Spring 2012 14
1/31/2013 CS 370, Spring 2012 15
1/31/2013 CS 370, Spring 2012 16
1/31/2013 CS 370, Spring 2012 17
1/31/2013 CS 370, Spring 2012 18
1/31/2013 CS 370, Spring 2012 19
video
2/14/2013 CS 370, Spring 2012 2
2/14/2013 CS 370, Spring 2012 3
2/14/2013 CS 370, Spring 2012 4
Available via the request.session Dictionary:
CS 370, Günay (Emory) Django Views/Templates Spring 2014 5 / 7
Available via the request.session Dictionary:
CS 370, Günay (Emory) Django Views/Templates Spring 2014 5 / 7
2/14/2013 CS 370, Spring 2012 5
2/14/2013 CS 370, Spring 2012 6
Add django.contrib.sessions to INSTALLED_APPS inside settings.py To create database tables, do: python manage.py syncdb
CS 370, Günay (Emory) Django Views/Templates Spring 2014 7 / 7
CS 370, Günay (Emory) Django Views/Templates Spring 2014 7 / 7
2/14/2013 CS 370, Spring 2012 7
1/31/2013 CS 370, Spring 2012 20