mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #11554: Several errors in Generic Views Documentation.
Thanks Ramiro. Refs #11477 - that ticket should have been marked a duplicate of #11554 git-svn-id: http://code.djangoproject.com/svn/django/trunk@11499 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7c53c2618d
commit
8da58e51ff
@ -150,7 +150,7 @@ be using these models::
|
|||||||
publisher = models.ForeignKey(Publisher)
|
publisher = models.ForeignKey(Publisher)
|
||||||
publication_date = models.DateField()
|
publication_date = models.DateField()
|
||||||
|
|
||||||
To build a list page of all books, we'd use a URLconf along these lines::
|
To build a list page of all publishers, we'd use a URLconf along these lines::
|
||||||
|
|
||||||
from django.conf.urls.defaults import *
|
from django.conf.urls.defaults import *
|
||||||
from django.views.generic import list_detail
|
from django.views.generic import list_detail
|
||||||
@ -176,7 +176,7 @@ version of the model's name.
|
|||||||
.. highlightlang:: html+django
|
.. highlightlang:: html+django
|
||||||
|
|
||||||
This template will be rendered against a context containing a variable called
|
This template will be rendered against a context containing a variable called
|
||||||
``object_list`` that contains all the book objects. A very simple template
|
``object_list`` that contains all the publisher objects. A very simple template
|
||||||
might look like the following::
|
might look like the following::
|
||||||
|
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
@ -217,7 +217,7 @@ Making "friendly" template contexts
|
|||||||
You might have noticed that our sample publisher list template stores all the
|
You might have noticed that our sample publisher list template stores all the
|
||||||
books in a variable named ``object_list``. While this works just fine, it isn't
|
books in a variable named ``object_list``. While this works just fine, it isn't
|
||||||
all that "friendly" to template authors: they have to "just know" that they're
|
all that "friendly" to template authors: they have to "just know" that they're
|
||||||
dealing with books here. A better name for that variable would be
|
dealing with publishers here. A better name for that variable would be
|
||||||
``publisher_list``; that variable's content is pretty obvious.
|
``publisher_list``; that variable's content is pretty obvious.
|
||||||
|
|
||||||
We can change the name of that variable easily with the ``template_object_name``
|
We can change the name of that variable easily with the ``template_object_name``
|
||||||
@ -241,14 +241,14 @@ Adding extra context
|
|||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
Often you simply need to present some extra information beyond that provided by
|
Often you simply need to present some extra information beyond that provided by
|
||||||
the generic view. For example, think of showing a list of all the other
|
the generic view. For example, think of showing a list of all the books on each
|
||||||
publishers on each publisher detail page. The ``object_detail`` generic view
|
publisher detail page. The ``object_detail`` generic view provides the
|
||||||
provides the publisher to the context, but it seems there's no way to get a list
|
publisher to the context, but it seems there's no way to get additional
|
||||||
of *all* publishers in that template.
|
information in that template.
|
||||||
|
|
||||||
But there is: all generic views take an extra optional parameter,
|
But there is: all generic views take an extra optional parameter,
|
||||||
``extra_context``. This is a dictionary of extra objects that will be added to
|
``extra_context``. This is a dictionary of extra objects that will be added to
|
||||||
the template's context. So, to provide the list of all publishers on the detail
|
the template's context. So, to provide the list of all books on the detail
|
||||||
detail view, we'd use an info dict like this:
|
detail view, we'd use an info dict like this:
|
||||||
|
|
||||||
.. parsed-literal::
|
.. parsed-literal::
|
||||||
|
Loading…
Reference in New Issue
Block a user