2
3
4
5
6 >> django-admin.py startproject mysite /mysite __init__.py manage.py settings.py urls.py
7 >> python manage.py syncdb >> python manage.py runserver «port number»
8
9
from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^polls/$', 'polls.views.index'), (r'^polls/(?P \d+)/$', 'polls.views.detail'), (r'^polls/(?P \d+)/results/$', 'polls.views.results'), (r'^polls/(?P \d+)/vote/$', 'polls.views.vote'), (r'^admin/', include(admin.site.urls)), ) 10
11 >> django-admin.py startapp myapp /myapp __init__.py models.py tests.py views.py
12
13
14
from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() 15
16
17
18
19
20
21
22
def example_view: template = get_template(”mytemplate.html”) #1 data = Context({ ’foo’: ’hello’, ’bar’: ’world’ }) #2 output = template.render(data) #3 return HttpResponse(output) #4 23
24
25
26
27
28
30
31
32
33 Application: mysite
34 >> django-admin.py startapp myapp
from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() from appengine_django.models import BaseModel from google.appengine.ext import db class Poll(BaseModel): question = db.StringProperty() pub_date = db.DateTimeProperty('date published') class Choice(BaseModel): poll = db.ReferenceProperty(Poll) choice = db.StringProperty() votes = db.IntegerProperty() 35
36
37 - url: /static static_dir: static
38 - url: /.* script: main.py
39 DATABASE_ENGINE = 'appengine' DEBUG = True INSTALLED_APPS = ['appengine_django'] MIDDLEWARE_CLASSES = () ROOT_URLCONF = 'urls' ### SETTINGS_MODULE = 'mysite.settings' ### SITE_ID = 1 ### TEMPLATE_DEBUG = True TIME_ZONE = 'UTC'
40
41
42