开发者

does the `context_instance=RequestContext(request)` use cookies in django

when i change the homepage view:

def home(request):
    return render_to_response('homepage.html'开发者_运维技巧)

to

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

the user who login my site will always login even when i close the web Browser(firefox)

why context_instance=RequestContext(request) can do this ? Does it use cookies ?

how long time it will maintain this state .

thanks

the homepage.html is :

{% 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 %}


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜