Accessing session variable in Django template with Google App Engine (Webapp) - Python
I have a Django template as my front-end. At the back-end, I used the 开发者_如何学JAVAsessions provided from Gaeutilities to store a variable (email).
Front-end:
{% if session.Email %}
<div id="entersite">WELCOME <em>{{session.Email}}</em></div>
{% else %}
<div id= "entersite"><a href="/login/" id= "entersite">Enter the Site</a></div>
{% endif %}
Back-end:
self.session = Session()
self.session['email'] = email
temp = os.path.join(os.path.dirname(__file__),'templates/index.htm')
outstr = template.render(temp, {})
self.response.out.write(outstr)
Problem: How do I access the stored session on the server side and use it on the Django template (front-end)?
Anybody can give an update on this qns?
You need to set your session object in a django template context, no?
template.render(temp, {'session':self.session})
By doing so, you are just rendering the template with the session value. What happens is that when I click on a link to another page, and from that page return back to the same template, the session value are not being displayed. This is because I did not render the session value to the template from the page. What I wanted to do is to create a session at the back-end and traverse several pages and when I go back to the template, the session value can still be retrieved. Any ideas?
精彩评论