Removed "Don't do that" from docs and error messages.
It's slightly aggressive and doesn't explain itself.
This commit is contained in:
parent
1487f16f2d
commit
2ea3fb3e63
|
@ -50,9 +50,10 @@ class View:
|
||||||
"""Main entry point for a request-response process."""
|
"""Main entry point for a request-response process."""
|
||||||
for key in initkwargs:
|
for key in initkwargs:
|
||||||
if key in cls.http_method_names:
|
if key in cls.http_method_names:
|
||||||
raise TypeError("You tried to pass in the %s method name as a "
|
raise TypeError(
|
||||||
"keyword argument to %s(). Don't do that."
|
'The method name %s is not accepted as a keyword argument '
|
||||||
% (key, cls.__name__))
|
'to %s().' % (key, cls.__name__)
|
||||||
|
)
|
||||||
if not hasattr(cls, key):
|
if not hasattr(cls, key):
|
||||||
raise TypeError("%s() received an invalid keyword %r. as_view "
|
raise TypeError("%s() received an invalid keyword %r. as_view "
|
||||||
"only accepts arguments that are already "
|
"only accepts arguments that are already "
|
||||||
|
|
|
@ -125,13 +125,6 @@ view function. The ``:question_id>`` part of the string defines the name that
|
||||||
will be used to identify the matched pattern, and the ``<int:`` part is a
|
will be used to identify the matched pattern, and the ``<int:`` part is a
|
||||||
converter that determines what patterns should match this part of the URL path.
|
converter that determines what patterns should match this part of the URL path.
|
||||||
|
|
||||||
There's no need to add URL cruft such as ``.html`` -- unless you want to, in
|
|
||||||
which case you can do something like this::
|
|
||||||
|
|
||||||
path('polls/latest.html', views.index),
|
|
||||||
|
|
||||||
But, don't do that. It's silly.
|
|
||||||
|
|
||||||
Write views that actually do something
|
Write views that actually do something
|
||||||
======================================
|
======================================
|
||||||
|
|
||||||
|
|
|
@ -228,9 +228,8 @@ model. In those situations, Django has to be able to see all the objects for
|
||||||
the model it is fetching, so that *anything* which is referred to can be
|
the model it is fetching, so that *anything* which is referred to can be
|
||||||
retrieved.
|
retrieved.
|
||||||
|
|
||||||
If you override the ``get_queryset()`` method and filter out any rows, Django
|
Therefore, you should not override ``get_queryset()`` to filter out any rows.
|
||||||
will return incorrect results. Don't do that. A manager that filters results
|
If you do so, Django will return incomplete results.
|
||||||
in ``get_queryset()`` is not appropriate for use as a base manager.
|
|
||||||
|
|
||||||
.. _calling-custom-queryset-methods-from-manager:
|
.. _calling-custom-queryset-methods-from-manager:
|
||||||
|
|
||||||
|
|
|
@ -495,10 +495,11 @@ Setup
|
||||||
datetimes safely, their representation should include the UTC offset, or
|
datetimes safely, their representation should include the UTC offset, or
|
||||||
their values should be in UTC (or both!).
|
their values should be in UTC (or both!).
|
||||||
|
|
||||||
Finally, our calendar system contains interesting traps for computers::
|
Finally, our calendar system contains interesting edge cases. For example,
|
||||||
|
you can't always subtract one year directly from a given date::
|
||||||
|
|
||||||
>>> import datetime
|
>>> import datetime
|
||||||
>>> def one_year_before(value): # DON'T DO THAT!
|
>>> def one_year_before(value): # Wrong example.
|
||||||
... return value.replace(year=value.year - 1)
|
... return value.replace(year=value.year - 1)
|
||||||
>>> one_year_before(datetime.datetime(2012, 3, 1, 10, 0))
|
>>> one_year_before(datetime.datetime(2012, 3, 1, 10, 0))
|
||||||
datetime.datetime(2011, 3, 1, 10, 0)
|
datetime.datetime(2011, 3, 1, 10, 0)
|
||||||
|
@ -507,9 +508,9 @@ Setup
|
||||||
...
|
...
|
||||||
ValueError: day is out of range for month
|
ValueError: day is out of range for month
|
||||||
|
|
||||||
(To implement this function, you must decide whether 2012-02-29 minus
|
To implement such a function correctly, you must decide whether 2012-02-29
|
||||||
one year is 2011-02-28 or 2011-03-01, which depends on your business
|
minus one year is 2011-02-28 or 2011-03-01, which depends on your business
|
||||||
requirements.)
|
requirements.
|
||||||
|
|
||||||
#. **How do I interact with a database that stores datetimes in local time?**
|
#. **How do I interact with a database that stores datetimes in local time?**
|
||||||
|
|
||||||
|
|
|
@ -143,8 +143,8 @@ class ViewTest(SimpleTestCase):
|
||||||
be named like a HTTP method.
|
be named like a HTTP method.
|
||||||
"""
|
"""
|
||||||
msg = (
|
msg = (
|
||||||
"You tried to pass in the %s method name as a keyword argument "
|
'The method name %s is not accepted as a keyword argument to '
|
||||||
"to SimpleView(). Don't do that."
|
'SimpleView().'
|
||||||
)
|
)
|
||||||
# Check each of the allowed method names
|
# Check each of the allowed method names
|
||||||
for method in SimpleView.http_method_names:
|
for method in SimpleView.http_method_names:
|
||||||
|
|
Loading…
Reference in New Issue