user object not available in template

25 views
Skip to first unread message

Drew Ferguson

unread,
Nov 25, 2016, 6:06:04 PM11/25/16
to Django users
Hi

Using Django 1.10 

In my templates there is no user object to provide user.is_authenticated

Is there something I have to do to turn this on?

My settings has this

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]


MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
]

Thanks

Drew

James Bennett

unread,
Nov 25, 2016, 6:24:30 PM11/25/16
to django...@googlegroups.com
The auth context processor provides it, but not as a variable named 'user'; instead it's attached to the 'request' variable, so what you want is '{% if request.user.is_authenticated }}'.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0392acda-3e6d-41d6-9a6f-1b2a07f9146f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Bennett

unread,
Nov 25, 2016, 6:25:24 PM11/25/16
to django...@googlegroups.com
Ah, never mind, misread the question.

Are you sure you're using a RequestContext?

Drew Ferguson

unread,
Nov 25, 2016, 6:43:01 PM11/25/16
to Django users
I just upgraded from 1.5 or something where the code worked fine

I'm not sure what has changed in 1.10 but everything is back to normal after I changed

def homepage(request):
    return render_to_response('xstatic_homepage.html', RequestContext(request))

to

def homepage(request):
    return render(request, 'xstatic_homepage.html')

Can someone explain this for me please?
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Matthew Pava

unread,
Nov 28, 2016, 9:21:39 AM11/28/16
to django...@googlegroups.com

Render_to_response no longer accepts a context instance parameter (or a “dirs” parameter).

https://docs.djangoproject.com/en/dev/releases/1.10/

 

I encourage you to read this document before performing an upgrade:

https://docs.djangoproject.com/en/dev/howto/upgrade-version/

 

In particular, read the release notes (as time consuming as it is) of each version between the two versions you are upgrading from and to.

https://docs.djangoproject.com/en/dev/releases/

Reply all
Reply to author
Forward
0 new messages