Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The django.contrib.auth.context_processors.auth sets the <code>{{ user }}</code> template context variable to either request.user or AnonymousUser. So, it overrides the <code>{{ user }}</code> context variable created by your DetailView:</p> <pre><code>def auth(request): """ Returns context variables required by apps that use Django's authentication system. If there is no 'user' attribute in the request, uses AnonymousUser (from django.contrib.auth). """ # If we access request.user, request.session is accessed, which results in # 'Vary: Cookie' being sent in every request that uses this context # processor, which can easily be every request on a site if # TEMPLATE_CONTEXT_PROCESSORS has this context processor added. This kills # the ability to cache. So, we carefully ensure these attributes are lazy. # We don't use django.utils.functional.lazy() for User, because that # requires knowing the class of the object we want to proxy, which could # break with custom auth backends. LazyObject is a less complete but more # flexible solution that is a good enough wrapper for 'User'. def get_user(): if hasattr(request, 'user'): return request.user else: from django.contrib.auth.models import AnonymousUser return AnonymousUser() return { 'user': SimpleLazyObject(get_user), 'messages': messages.get_messages(request), 'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(), } </code></pre> <p>You can work around the issue by <a href="https://docs.djangoproject.com/en/dev/topics/class-based-views/#making-friendly-template-contexts" rel="noreferrer">setting context_object_name</a>. For example, this will enable the <code>{{ user_object }}</code> context variable, set to the user of the DetailView:</p> <pre><code>url( r'^users/(?P&lt;pk&gt;\d+)/$', DetailView.as_view( model = User, template_name = 'doors/users/detail.html', context_object_name = 'user_object' ), name = 'users_detail' ) </code></pre> <p>Dig deeper, read the documentation for <a href="https://docs.djangoproject.com/en/dev/ref/class-based-views/#django.views.generic.detail.SingleObjectMixin.get_context_object_name" rel="noreferrer">get_context_object_name()</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload