Opened 2 years ago

Closed 2 years ago

#20733 closed Bug (fixed)

Minor code error in doc page for DetailView

Reported by: ijl20@… Owned by: nobody
Component: Documentation Version: 1.5
Severity: Normal Keywords: DetailView
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation:
Needs tests: Patch needs improvement:
Easy pickings: yes UI/UX: no

Description

Re:
https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#django.views.generic.detail.DetailView

Current (2013-July-11) docs give example myapp/article_detail.html:

<h1>{{ object.headline }}</h1>
<p>{{ object.content }}</p>
<p>Reporter: {{ object.reporter }}</p>
<p>Published: {{ object.pub_date|date }}</p>
<p>Date: {{ object.now|date }}</p>

the last line should be

<p>Date: {{ now|date }}</p>

Because views.py only adds 'now' to the context, not as a new attribute of the object being rendered, as below. Currently, object.now displays as 'blank'.

    def get_context_data(self, **kwargs):
        context = super(ArticleDetailView, self).get_context_data(**kwargs)
        context['now'] = timezone.now()
        return context

regards - Ian Lewis, Cambridge

Change History (1)

comment:1 Changed 2 years ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In f93b2fe7e698a9dd48d839465c75b16013b0f652:

[1.6.x] Fixed #20733 -- Typo in docs/ref/class-based-views/generic-display.txt

Thanks ijl20@ for the report.

Backport of ecd746191c from master

Note: See TracTickets for help on using tickets.
Back to Top