Reminders
Time to deploy! Projects are due before class on Thursday!
CS370, Günay (Emory) Spring 2015 1 / 9
Reminders Time to deploy! Projects are due before class on Thursday! - - PowerPoint PPT Presentation
Reminders Time to deploy! Projects are due before class on Thursday! CS370, Gnay (Emory) Spring 2015 1 / 9 Reminders Time to deploy! Projects are due before class on Thursday! Ill make a Piazza post for you to put your links and description
Time to deploy! Projects are due before class on Thursday!
CS370, Günay (Emory) Spring 2015 1 / 9
Time to deploy! Projects are due before class on Thursday! I’ll make a Piazza post for you to put your links and description for voting in WebIdol!
CS370, Günay (Emory) Spring 2015 1 / 9
CS370 SE Practice & Startup, Cengiz Günay (Some slides courtesy of Eugene Agichstein and the Internets)
CS370, Günay (Emory) Django Views/Templates/Data/Sessions Spring 2015 2 / 9
1/31/2013 CS 370, Spring 2012 2
urlpatterns = patterns('', url(r'^polls/$', 'polls.views.index'), url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'), url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'), url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'), url(r'^admin/', include(admin.site.urls)), )
1/31/2013 CS 370, Spring 2012 3
1/31/2013 CS 370, Spring 2012 5
– Django loads the polls Python module – finds variable named urlpatterns and traverses the regular expressions in order – First matching regex: r'^polls/(?P<poll_id>\d+)/$‘
detail( request=<HttpRequest object> , poll_id='23‘ )
1/31/2013 CS 370, Spring 2012 4
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
{% if latest_poll_list %} <ul> {% for poll in latest_poll_list %} <li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li> {% endfor %} </ul> {% else %} <p>No polls are available.</p> {% endif %}
1/31/2013 CS 370, Spring 2012 10
1/31/2013 CS 370, Spring 2012 11
– The date filter formats dates in a given format, as specified by that
reference to Unix pipes.
1/31/2013 CS 370, Spring 2012 12
http://www.djangobook.com/en/2.0/chapter04/
1/31/2013 CS 370, Spring 2012 13
1/31/2013 CS 370, Spring 2012 14
(r'^wiki/', include('blog.wiki.urls')) )
– https://docs.djangoproject.com/en/dev/topics/http/urls/
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
2/12/2013 CS 370, Spring 2012 2
Made with Dia Diamonds indicate aggregation
CS370, Günay (Emory) Django Views/Templates/Data/Sessions Spring 2015 5 / 9
Made with Dia Diamonds indicate aggregation
CS370, Günay (Emory) Django Views/Templates/Data/Sessions Spring 2015 5 / 9
Made with Dia Diamonds indicate aggregation
CS370, Günay (Emory) Django Views/Templates/Data/Sessions Spring 2015 5 / 9
class Publisher(models.Model): name = models.CharField(maxlength=30) … website = models.URLField() #implicit: ID (primary key) class Author(models.Model): first_name = models.CharField(maxlength=30) last_name = models.CharField(maxlength=40) email = models.EmailField() headshot = models.ImageField(upload_to='/tmp') class Book(models.Model): title = models.CharField(maxlength=100) authors = models.ManyToManyField(Author) publisher = models.ForeignKey(Publisher) publication_date = models.DateField()
2/12/2013 CS 370, Spring 2012 3
– publisher = models.ForeignKey(Publisher)
2/12/2013 CS 370, Spring 2012 4
2/12/2013 CS 370, Spring 2012 5
2/12/2013 CS 370, Spring 2012 6
2/12/2013 CS 370, Spring 2012 7
2/12/2013 CS 370, Spring 2012 8
2/12/2013 CS 370, Spring 2012 9
2/12/2013 CS 370, Spring 2012 10
2/12/2013 CS 370, Spring 2012 11
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:
Available via the request.session Dictionary:
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
2/14/2013 CS 370, Spring 2012 7
1/31/2013 CS 370, Spring 2012 20