manger methods general utility helper function forms Business logic is the part of the program that encodes the real- world business rules that determine how data can be created, displayed, stored, and changed……. (From wikipedia)
polls/views.py … from django.views import generic from polls.models import Question class IndexView(generic.ListView): template_name = 'polls/index.html' context_object_name = 'latest_question_list' def get_queryset(self): """Return the last five published questions.""" return Question.objects.order_by('-pub_date')[:5] class DetailView(generic.DetailView): model = Question template_name = 'polls/detail.html' class ResultsView(generic.DetailView): model = Question template_name = 'polls/results.html'
CBVs For past project: FBVs for most views, CBVs only for views that need to be subclassed. Write custom 403, 404, and 500 error handlers: FBVs # root URLconf handler500 = 'mysite.views.my_custom_error_view'
even if different applications use the same URL names. are specified using the ':' operator. For example, the main index page of the admin application is referenced using 'admin:index'. This indicates a namespace of 'admin', and a named URL of ‘index'. can also be nested. # EXAMPLE 7.3 # urls.py at root of project from django.conf.urls import include, url urlpatterns += patterns('', url(r'^tastings/', include('tastings.urls', namespace='tastings')), )
even if different applications use the same URL names. are specified using the ':' operator. For example, the main index page of the admin application is referenced using 'admin:index'. This indicates a namespace of 'admin', and a named URL of ‘index'. can also be nested. # EXAMPLE 7.3 # urls.py at root of project from django.conf.urls import include, url urlpatterns += patterns('', url(r'^tastings/', include('tastings.urls', namespace='tastings')), ) # EXAMPLE 7.4 # tastings/views.py snippet …… class TasteUpdateView(UpdateView): model = Tasting def get_success_url(self): return reverse("tastings:detail", kwargs={"pk": self.object.pk})
URL names Increases interoperability with Third-party libraries Easier searches, upgrades, and refactors Allow for more app and template reverse tricks
design a loosely coupled system is one in which each of its components has, or makes use of, little or no knowledge of the definitions of other separate components ….… (From wikipedia)