Monday, November 28, 2016

RE: user object not available in template

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/

 

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Drew Ferguson
Sent: Friday, November 25, 2016 5:43 PM
To: Django users
Subject: Re: user object not available in template

 

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?


On Saturday, 26 November 2016 00:25:24 UTC+1, James Bennett wrote:

Ah, never mind, misread the question.

 

Are you sure you're using a RequestContext?

 

On Fri, Nov 25, 2016 at 3:23 PM, James Bennett <ubern...@gmail.com> wrote:

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 }}'.

 

On Fri, Nov 25, 2016 at 3:02 PM, Drew Ferguson <blac...@gmail.com> wrote:

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

--
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...@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.

 

 

--
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-users@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/757507d3-bbdf-4408-9820-6f93bf069440%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment