mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #11416 -- Restored use of the never_cache decorator on admin views. Thanks to Ramiro Morales and Michael Newmann for their work on the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11229 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
33ea28c2b2
commit
e992e57d3e
3 changed files with 111 additions and 17 deletions
|
@ -762,12 +762,19 @@ documented in :ref:`topics-http-urls`::
|
|||
anything, so you'll usually want to prepend your custom URLs to the built-in
|
||||
ones.
|
||||
|
||||
Note, however, that the ``self.my_view`` function registered above will *not*
|
||||
have any permission check done; it'll be accessible to the general public. Since
|
||||
this is usually not what you want, Django provides a convience wrapper to check
|
||||
permissions. This wrapper is :meth:`AdminSite.admin_view` (i.e.
|
||||
``self.admin_site.admin_view`` inside a ``ModelAdmin`` instance); use it like
|
||||
so::
|
||||
However, the ``self.my_view`` function registered above suffers from two
|
||||
problems:
|
||||
|
||||
* It will *not* perform and permission checks, so it will be accessible to
|
||||
the general public.
|
||||
* It will *not* provide any header details to prevent caching. This means if
|
||||
the page retrieves data from the database, and caching middleware is
|
||||
active, the page could show outdated information.
|
||||
|
||||
Since this is usually not what you want, Django provides a convenience wrapper
|
||||
to check permissions and mark the view as non-cacheable. This wrapper is
|
||||
:meth:`AdminSite.admin_view` (i.e. ``self.admin_site.admin_view`` inside a
|
||||
``ModelAdmin`` instance); use it like so:
|
||||
|
||||
class MyModelAdmin(admin.ModelAdmin):
|
||||
def get_urls(self):
|
||||
|
@ -781,7 +788,14 @@ Notice the wrapped view in the fifth line above::
|
|||
|
||||
(r'^my_view/$', self.admin_site.admin_view(self.my_view))
|
||||
|
||||
This wrapping will protect ``self.my_view`` from unauthorized access.
|
||||
This wrapping will protect ``self.my_view`` from unauthorized access and will
|
||||
apply the ``django.views.decorators.cache.never_cache`` decorator to make sure
|
||||
it is not cached if the cache middleware is active.
|
||||
|
||||
If the page is cacheable, but you still want the permission check to be performed,
|
||||
you can pass a ``cacheable=True`` argument to :meth:`AdminSite.admin_view`::
|
||||
|
||||
(r'^my_view/$', self.admin_site.admin_view(self.my_view, cacheable=True))
|
||||
|
||||
.. method:: ModelAdmin.formfield_for_foreignkey(self, db_field, request, **kwargs)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue