diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-09-23 22:50:05 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-09-23 22:50:05 +0000 |
| commit | b7528320b64f3e818f798daa7235f7b5721d4ac2 (patch) | |
| tree | 356e0078a67d1503ee6e023e69ec2e2b633bd599 /docs/overview.txt | |
| parent | 3dcdce4d63e155d79a7ece80b14c5ab4358c98a9 (diff) | |
Changed overview and tutorial docs to use render_to_response and get_object_or_404, to cut down on code
git-svn-id: http://code.djangoproject.com/svn/django/trunk@678 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/overview.txt')
| -rw-r--r-- | docs/overview.txt | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/docs/overview.txt b/docs/overview.txt index a84a9ea624..9f0b1db521 100644 --- a/docs/overview.txt +++ b/docs/overview.txt @@ -195,20 +195,10 @@ Generally, a view retrieves data according to the parameters, loads a template and renders the template with the retrieved data. Here's an example view for article_detail from above:: - from django.models.news import articles - def article_detail(request, year, month, article_id): # Use the Django API to find an object matching the URL criteria. - try: - a = articles.get_object(pub_date__year=year, pub_date__month=month, pk=article_id) - except articles.ArticleDoesNotExist: - raise Http404 - t = template_loader.get_template('news/article_detail') - c = Context(request, { - 'article': a, - }) - content = t.render(c) - return HttpResponse(content) + a = get_object_or_404(articles, pub_date__year=year, pub_date__month=month, pk=article_id) + return render_to_response('news/article_detail', {'article': a}) This example uses Django's template system, which has several key features. @@ -261,7 +251,6 @@ template has to define only what's unique to that template. Here's what the "base" template might look like:: - <html> <head> <title>{% block title %}{% endblock %}</title> |
