class Poll(Model):
question = CharField(maxlength=200)
pub_date = DateTimeField('date published')
class Choice(Model):
poll = ForeignKey(Poll)
choice = CharField(maxlength=200)
votes = IntegerField()
BEGIN;
CREATE TABLE quot;polls_pollquot; (
quot;idquot; serial NOT NULL PRIMARY KEY,
quot;questionquot; varchar(200) NOT NULL,
quot;pub_datequot; timestamp with time zone
NOT NULL
);
CREATE TABLE quot;polls_choicequot; (
quot;idquot; serial NOT NULL PRIMARY KEY,
quot;poll_idquot; integer NOT NULL
REFERENCES quot;polls_pollsquot; (quot;idquot;),
quot;choicequot; varchar(200) NOT NULL,
quot;votesquot; integer NOT NULL
);
COMMIT;
<h1>Hello World!</h1>
<p>Today is {{ today|date:”jS F, Y” }}</p>
{% if edibles %}
<ul>
{% for fruit in edibles %}
<li>{{ fruit }}</li>
{% endfor %}
</ul>
{% endif %}
<h1>Hello World!</h1>
<p>Today is 20th April, 2006</p>
<ul>
<li>pear</li>
<li>apple</li>
<li>orange</li>
</ul>
def hello(request):
t = get_template('hello.html')
c = Context({
'today': datetime.date.today(),
'edibles': ['pear', 'apple', 'orange']
})
return HttpResponse(t.render(c))
All you really need are
variables, conditionals
and loops
Essential ingredients
HTTP handling
URL dispatching
Templating
Documentation
Database access (optional)
... no wonder there are so many frameworks!
Extras
Forms are boring
1. Display form
2. Validate submitted data
3. If errors, redisplay with:
3.1. Contextual error messages
3.2. Correct fields pre-filled
4. ... do something useful!
Model validation rules
+ the Manipulator API
do all of this for you
django.contrib.admin
does even more
class Poll(Model):
question = CharField(maxlength=200)
pub_date = DateTimeField('date published')
class Admin:
list_display = ('question', 'pub_date')
class Choice(Model):
poll = ForeignKey(Poll)
choice = CharField(maxlength=200)
votes = IntegerField()
class Admin:
pass
{{ page.content|textile }}
{% comment_form for news.stories
story.id with is_public yes
photos_optional thumbs,200,400
ratings_optional
scale:1-5|first_option|second_option %}
from django import template
register = template.Library()
def textile(value):
try:
import textile
except ImportError:
return value
else:
return textile.textile(value)
register.filter(textile)
i18n and l10n
Bengali Japanese
Czech Dutch
Welsh Norwegian
Danish Brazilian
German Romanian
Greek Russian
English Slovak
Spanish Slovenian
French Serbian
Galician Swedish
Hebrew Ukrainian
Icelandic Simplified Chinese
Italian Traditional Chinese
Authentication and
authorisation
Community
?
It’s a matter of taste
HTTP handling
What happens to form variables? GET vs POST
How to handle /path?foo=1&foo=2
How to send back non-standard responses
Different Content-Type (and other) headers
404s, 500s
Session support?
Database handling
To ORM or not to ORM?
Pluralisation?
Handling joins
Lookup syntax
When should you fall back on raw SQL?
Templating
Plain text or XML?
Markup visible on the page or hidden in
HTML attributes?
Logic in the template vs logic in the view/
controller
Safe (and limited) or unsafe (and more
powerful)
Language extension mechanism?
Where’s the line?
Authentication and authorisation?
Automated admin / forms?
i18n and l10n?
JavaScript and Ajax?
zunita http://ringtones-x.com/ | www.freeringtonesforatt.org/ 2 years ago
Dave (a web designer currently working on : www.freeringtonesforverizon.net/ ) 2 years ago