WADS 2007 Django PDF
WADS 2007 Django PDF
Framework
Web application development seminar, Fall 2007
Tampere University of Technology
1
Hypermedia Laboratory Tampere University of Technology
http://www.djangoproject.com/
Django The MacGyver of
Web Frameworks
http://www.unessa.net/en/hoyci/2007/
01/django-macgyver-web-frameworks/
2
Hypermedia Laboratory
Image from: WikipediaTampere University of Technology
In this presentation
3
Hypermedia Laboratory Tampere University of Technology
A short history of Django
4
Hypermedia Laboratory Tampere University of Technology
Key Philosophies
As according to (http://www.djangoproject.com/):
Loose Coupling
Clear interfaces between different layers of the framework
Less code
Especially by utilising Python's dynamic capabilities
Quick [Web] Development
Focus on outcome, not on the details
Dont Repeat Yourself
Single placement for every distinct concept and/or data
An MTV(?) (Model-Template-View) framework
Rather thanMVC (Model-View-Controller)
As according to (http://www.djangoproject.com/):
Template system
providing means to separate design, content and code
6
Hypermedia Laboratory Tampere University of Technology
Key Features (2/2)
Cache support
Instructions are provided for integrating Memcached
(http://www.danga.com/memcached/) into a Django app
7
Hypermedia Laboratory Tampere University of Technology
Example: Poll application in Django (1/7)
8
Hypermedia Laboratory Tampere University of Technology
Example: Poll application in Django (2/7)
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Admin:
pass
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
9
Hypermedia Laboratory Tampere University of Technology
Example: Poll application in Django (3/7)
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
output = ', '.join([p.question for p in latest_poll_list])
return HttpResponse(output)
10
Hypermedia Laboratory Tampere University of Technology
Example: Poll application in Django (4/7)
{% if latest_poll_list %}
<ul>
{% for poll in latest_poll_list %}
<li>{{ poll.question }}</li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
11
Hypermedia Laboratory Tampere University of Technology
Example: Poll application in Django (5/7)
BEGIN;
CREATE TABLE "polls_poll" (
"id" serial NOT NULL PRIMARY KEY,
"question" varchar(200) NOT NULL,
"pub_date" timestamp with time zone NOT NULL
);
CREATE TABLE "polls_choice" (
"id" serial NOT NULL PRIMARY KEY,
"poll_id" integer NOT NULL REFERENCES "polls_poll" ("id"),
"choice" varchar(200) NOT NULL,
"votes" integer NOT NULL
);
COMMIT;
12
Hypermedia Laboratory Tampere University of Technology
Example: Poll application in Django (6/7)
<ul>
<li>What is your favourite food?</li>
<li>What is your favourite movie?</li>
<li>What is up?</li>
<li>If you had more time, you would dedicate it to what?</li>
</ul>
13
Hypermedia Laboratory Tampere University of Technology
Example: Poll application in Django (7/7)
14
Hypermedia Laboratory Tampere University of Technology
Example: Inserting doctest to Poll Model
15
Hypermedia Laboratory Tampere University of Technology
Discussion
development?
What if database bindings are complex?
16
Hypermedia Laboratory Tampere University of Technology
Questions
Question?
Comments?
Discussion!