Pregunta

cuando cambio la vista página de inicio:

def home(request):
    return render_to_response('homepage.html')

a

def home(request):
    return render_to_response('homepage.html',context_instance=RequestContext(request))

la user quien Identificación Red será siempre de inicio de sesión, incluso cuando cierro el navegador web (Firefox)

¿Por qué context_instance=RequestContext(request) puede hacer esto? ¿Utiliza cookies?

cómo mucho tiempo se mantendrá este estado.

gracias

la homepage.html es:

{% if user.is_authenticated %}
    <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
{% else %}
    <p>Welcome, new user. Please <a href="/account/login_view">login</a></p>
{% endif %}
¿Fue útil?

Solución

Adding the RequestContext does not change the user's logged-in state at all. And your question about cookies makes no sense at all. What the RequestContext does is make certain variables accessible in the template context - among them, assuming you have the auth context processor enabled, is a user variable.

Without the RequestContext, the user is still logged in, but you don't pass the user variable to the context, so your if statement evaluates to False. Nothing to do with the user's actual status at all.

Otros consejos

If you add context_instance=RequestContext(request) context from the context processors you have defined in your settings.py will be added to the template, in your case this includes the current user object in user. If you remove it, the variable doesn't exist, but inside the template this doesn't raise an exception but the HTML for the not-logged in user is rendered!

The user information is stored in a session, which uses cookies.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top