際際滷

際際滷Share a Scribd company logo
You¨ve done the Django tutorial.
What next?




                                           Andy McKay
                                   Clearwind Consulting
                                           @clearwind
build something
my opinions, likely wrong
1. Setting up
2. Writing models
3. Middle years
4. Avoid
5. Tools
Part I: Setting up
app vs project vs...
past caring
app directory
(a). base templates
(b). context processor
http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-
                            context-processors
def context(request):
    data = {}
    return data
(c). render shortcuts
eg: http://www.djangosnippets.org/snippets/1022/
(d). site constants
(e) your middleware
http://docs.djangoproject.com/en/1.1/topics/http/middleware/#writing-your-
                             own-middleware
(f) your auth. backend
http://docs.djangoproject.com/en/dev/topics/auth/#topics-auth
(g) base classes
model base class
class Base(models.Model):
  class Meta:
    abstract = True
form base class
class Form(forms.Form):
! pass

class ModelForm(forms.ModelForm):
! pass
Part 2: Writing models
(a) ?xtures
not just for testing
create data in admin
manage.py dumpdata
(b) migration
during development
reset script
http://www.agmweb.ca/blog/andy/2154/
drop db, create db,
syncdb, load ?xtures,
start up server etc...
my work?ow
1. create app within project
2. de?ne models
3. access admin
4. smoke test models
5. alter, run ^reset ̄
6. access admin (back to 4 until happy)
7. enter sample data
8. dump data to ?xtures
9. add ?xture loading to ^reset ̄
10. continue... write tests and retail view
at some point... beta?
South
http://south.aeracode.org/
Part 3: The middle years
(a) signals
great for decoupling
http://docs.djangoproject.com/en/dev/ref/signals/
                   #ref-signals
signals.pre_save.connect(
! add_profile,
! sender=User)
custom signals
http://docs.djangoproject.com/en/dev/topics/signals/#de?ning-and-sending-
                                 signals
(b) URLs
always use named urls
http://docs.djangoproject.com/en/dev/topics/http/urls/#url
urlpatterns = patterns('',
    url(/slideshow/youve-done-the-django-tutorial-what-next/3393961/r&),
    ...
)
姻艶厩艶姻壊艶(^馨温庄稼-厩庄艶敬 ̄)
{% url main-view %}
(c) class based views
   http://www.slideshare.net/simon/
     classbased-views-with-django
def boring(request):
    ...
    return some_html
class boring:
    def get(request):
        ...
        return some_html
Part 4: Avoid these
generic views
http://docs.djangoproject.com/en/dev/ref/generic-views/
push logic into urls,
always need rewriting
custom template tags
      (maybe)
complicated templates
{% div %}
  {% dl %}
    {% dt %}Name{% enddt %}
    {% dd %}Definition{% enddd %}
  {% enddl %}
{% enddiv %}
some of django.contrib...
comments
Part 5: Debug Tools
pdb
http://docs.python.org/library/pdb.html
pdb
http://docs.python.org/library/pdb.html
       (not optional)
ipython
http://ipython.scipy.org/moin/
ipdb
http://pypi.python.org/pypi/ipdb
django debug toolbar
http://github.com/robhudson/django-debug-toolbar
command extensions
http://code.google.com/p/django-command-extensions/
You've done the Django Tutorial, what next?
You've done the Django Tutorial, what next?
You've done the Django Tutorial, what next?
You've done the Django Tutorial, what next?
arecibo
http://areciboapp.com
      (disclaimer)
Fin. Questions?




                          Andy McKay
                  Clearwind Consulting
                          @clearwind

More Related Content

You've done the Django Tutorial, what next?