You've done the Django Tutorial, what next?

Post on 19-May-2015

1.471 views 2 download

Tags:

description

Some suggestions on where to look next when building that next Django site

Transcript of You've done the Django Tutorial, what next?

You’ve done the Django tutorial.What next?

Andy McKayClearwind Consulting

@clearwind

build something

my opinions, likely wrong

1. Setting up2. Writing models3. Middle years4. Avoid5. Tools

Part I: Setting up

app vs project vs...

past caring

app directory

(a). base templates

def context(request): data = {} return data

(c). render shortcutseg: http://www.djangosnippets.org/snippets/1022/

(d). site constants

(f) your auth. backendhttp://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) fixtures

not just for testing

create data in admin

manage.py dumpdata

(b) migration

during development

reset scripthttp://www.agmweb.ca/blog/andy/2154/

drop db, create db, syncdb, load fixtures, start up server etc...

my workflow

1. create app within project2. define models3. access admin4. smoke test models5. alter, run “reset”6. access admin (back to 4 until happy)7. enter sample data8. dump data to fixtures9. add fixture loading to “reset”10. continue... write tests and retail view

at some point... beta?

Southhttp://south.aeracode.org/

Part 3: The middle years

(a) signals

signals.pre_save.connect(! add_profile, ! sender=User)

(b) URLs

always use named urlshttp://docs.djangoproject.com/en/dev/topics/http/urls/#url

urlpatterns = patterns('', url(r'^index/$', index_view, name="main-view"), ...)

reverse(“main-view”)

{% url main-view %}

def boring(request): ... return some_html

class boring: def get(request): ... return some_html

Part 4: Avoid these

generic viewshttp://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

pdbhttp://docs.python.org/library/pdb.html

pdbhttp://docs.python.org/library/pdb.html

(not optional)

ipythonhttp://ipython.scipy.org/moin/

ipdbhttp://pypi.python.org/pypi/ipdb

django debug toolbarhttp://github.com/robhudson/django-debug-toolbar

command extensionshttp://code.google.com/p/django-command-extensions/

arecibohttp://areciboapp.com

(disclaimer)

Fin. Questions?

Andy McKayClearwind Consulting

@clearwind